class CZMQ::FFI::ZhttpRequest
Http request that can be received from zhttp_server or sent to zhttp_client. Class can be reused between send & recv calls. Headers and Content is being destroyed after every send call. @note This class is 100% generated using zproject.
Public Class Methods
@param ptr [::FFI::Pointer] @return [Proc]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 37 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.zhttp_request_destroy ptr_ptr end end
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 26 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end
Create a new http request. @return [CZMQ::ZhttpRequest]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 80 def self.new() ptr = ::CZMQ::FFI.zhttp_request_new() __new ptr end
Self test of this class.
@param verbose [Boolean] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 300 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zhttp_request_test(verbose) result end
Public Instance Methods
Return internal pointer @return [::FFI::Pointer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 50 def __ptr raise DestroyedError unless @ptr @ptr end
Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object
and thus makes it unusable.
@return [::FFI::MemoryPointer] the pointer pointing to a pointer
pointing to the native object
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 61 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end
Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native
object will be freed by other means.
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 73 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end
Get the content of the request.
@return [String]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 218 def content() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_content(self_p) result end
Get the content length of the request
@return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 197 def content_length() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_content_length(self_p) result end
Get the request content type
@return [String]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 176 def content_type() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_content_type(self_p) result end
Destroy an http request.
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 88 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zhttp_request_destroy(self_p) result end
Get the content of the request.
@return [::FFI::AutoPointer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 228 def get_content() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_get_content(self_p) result = ::FFI::AutoPointer.new(result, LibC.method(:free)) result end
Get the headers of the request
@return [Zhash]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 207 def headers() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_headers(self_p) result = Zhash.__new result, false result end
Match the path of the request. Support wildcards with '%s' symbol inside the match string. Matching wildcards until the next '/', '?' or '0'. On successful match the variadic arguments will be filled with the matching strings. On successful match the method is modifying the url field and break it into substrings. If you need to use the url, do it before matching or take a copy.
User must not free the variadic arguments as they are part of the url.
To use the percent symbol, just double it, e.g “%%something”.
Example: if (zhttp_request_match (request, “POST”, “/send/%s/%s”, &name, &id))
@param method [String, to_s, nil] @param path [String, to_s, nil] @param args [Array<Object>] see github.com/ffi/ffi/wiki/examples#using-varargs @return [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 289 def match(method, path, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_match(self_p, method, path, *args) result end
Get the request method
@return [String]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 132 def method() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_method(self_p) result end
@return [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 45 def null? !@ptr or @ptr.null? end
Receive a new request from zhttp_server. Return the underlying connection if successful, to be used when calling zhttp_response_send.
@param sock [Zsock, #__ptr] @return [::FFI::Pointer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 100 def recv(sock) raise DestroyedError unless @ptr self_p = @ptr sock = sock.__ptr if sock result = ::CZMQ::FFI.zhttp_request_recv(self_p, sock) result end
Set the content to NULL
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 264 def reset_content() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_reset_content(self_p) result end
Send a request to zhttp_client. Url and the request path will be concatenated. This behavior is useful for url rewrite and reverse proxy.
Send also allow two user provided arguments which will be returned with the response. The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an arg.
@param client [ZhttpClient, #__ptr] @param timeout [Integer, to_int, to_i] @param arg [::FFI::Pointer, to_ptr
] @param arg2 [::FFI::Pointer, to_ptr
] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 120 def send(client, timeout, arg, arg2) raise DestroyedError unless @ptr self_p = @ptr client = client.__ptr if client timeout = Integer(timeout) result = ::CZMQ::FFI.zhttp_request_send(self_p, client, timeout, arg, arg2) result end
Set the content of the request. Content must by dynamically allocated string. Takes ownership of the content.
@param content [::FFI::Pointer, to_ptr
] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 242 def set_content(content) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_set_content(self_p, content) result end
Set the content of the request.. The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
@param content [String, to_s, nil] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 254 def set_content_const(content) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_set_content_const(self_p, content) result end
Set the request content type
@param content_type
[String, to_s, nil] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 187 def set_content_type(content_type) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_set_content_type(self_p, content_type) result end
Set the request method
@param method [String, to_s, nil] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 143 def set_method(method) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_set_method(self_p, method) result end
Set the request url When sending a request to http client this should be full url.
@param url [String, to_s, nil] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 166 def set_url(url) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_set_url(self_p, url) result end
So external Libraries can just pass the Object to a FFI
function which expects a :pointer
Get the request url. When receiving a request from http server this is only the path part of the url.
@return [String]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb, line 154 def url() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_request_url(self_p) result end