Class: CZMQ::FFI::ZhttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb

Overview

Note:

This class is 100% generated using zproject.

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.

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ ZhttpRequest

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


26
27
28
29
30
31
32
33
34
# 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

Class Method Details

.__newObject



20
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 20

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


37
38
39
40
41
42
43
44
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 37

def self.create_finalizer_for(ptr)
  ptr_ptr = ::FFI::MemoryPointer.new :pointer

  Proc.new do
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.zhttp_request_destroy ptr_ptr
  end
end

.newCZMQ::ZhttpRequest

Create a new http request.

Returns:

  • (CZMQ::ZhttpRequest)


81
82
83
84
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 81

def self.new()
  ptr = ::CZMQ::FFI.zhttp_request_new()
  __new ptr
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


301
302
303
304
305
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 301

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zhttp_request_test(verbose)
  result
end

Instance Method Details

#__ptr::FFI::Pointer Also known as: to_ptr

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



51
52
53
54
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 51

def __ptr
  raise DestroyedError unless @ptr
  @ptr
end

#__ptr_give_ref::FFI::MemoryPointer

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



62
63
64
65
66
67
68
69
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 62

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

#__undef_finalizervoid

Note:

Only use this if you need to and can guarantee that the native object will be freed by other means.

This method returns an undefined value.

Undefines the finalizer for this object.



74
75
76
77
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 74

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#contentString

Get the content of the request.

Returns:

  • (String)

Raises:



219
220
221
222
223
224
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 219

def content()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_content(self_p)
  result
end

#content_lengthInteger

Get the content length of the request

Returns:

  • (Integer)

Raises:



198
199
200
201
202
203
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 198

def content_length()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_content_length(self_p)
  result
end

#content_typeString

Get the request content type

Returns:

  • (String)

Raises:



177
178
179
180
181
182
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 177

def content_type()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_content_type(self_p)
  result
end

#destroyvoid

This method returns an undefined value.

Destroy an http request.



89
90
91
92
93
94
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 89

def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zhttp_request_destroy(self_p)
  result
end

#get_content::FFI::AutoPointer

Get the content of the request.

Returns:

  • (::FFI::AutoPointer)

Raises:



229
230
231
232
233
234
235
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 229

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

#headersZhash

Get the headers of the request

Returns:

Raises:



208
209
210
211
212
213
214
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 208

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(method, path, *args) ⇒ Boolean

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))

Parameters:

Returns:

  • (Boolean)

Raises:



290
291
292
293
294
295
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 290

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

#methodString

Get the request method

Returns:

  • (String)

Raises:



133
134
135
136
137
138
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 133

def method()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_method(self_p)
  result
end

#null?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 46

def null?
  !@ptr or @ptr.null?
end

#recv(sock) ⇒ ::FFI::Pointer

Receive a new request from zhttp_server. Return the underlying connection if successful, to be used when calling zhttp_response_send.

Parameters:

Returns:

  • (::FFI::Pointer)

Raises:



101
102
103
104
105
106
107
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 101

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

#reset_contentvoid

This method returns an undefined value.

Set the content to NULL

Raises:



265
266
267
268
269
270
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 265

def reset_content()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_reset_content(self_p)
  result
end

#send(client, timeout, arg, arg2) ⇒ Integer

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.

Parameters:

Returns:

  • (Integer)

Raises:



121
122
123
124
125
126
127
128
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 121

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_content(content) ⇒ void

This method returns an undefined value.

Set the content of the request. Content must by dynamically allocated string. Takes ownership of the content.

Parameters:

  • content (::FFI::Pointer, #to_ptr)

Raises:



243
244
245
246
247
248
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 243

def set_content(content)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_set_content(self_p, content)
  result
end

#set_content_const(content) ⇒ void

This method returns an undefined value.

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.

Parameters:

  • content (String, #to_s, nil)

Raises:



255
256
257
258
259
260
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 255

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_content_type(content_type) ⇒ void

This method returns an undefined value.

Set the request content type

Parameters:

  • content_type (String, #to_s, nil)

Raises:



188
189
190
191
192
193
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 188

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_method(method) ⇒ void

This method returns an undefined value.

Set the request method

Parameters:

  • method (String, #to_s, nil)

Raises:



144
145
146
147
148
149
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 144

def set_method(method)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_set_method(self_p, method)
  result
end

#set_url(url) ⇒ void

This method returns an undefined value.

Set the request url When sending a request to http client this should be full url.

Parameters:

  • url (String, #to_s, nil)

Raises:



167
168
169
170
171
172
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 167

def set_url(url)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_set_url(self_p, url)
  result
end

#urlString

Get the request url. When receiving a request from http server this is only the path part of the url.

Returns:

  • (String)

Raises:



155
156
157
158
159
160
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_request.rb', line 155

def url()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zhttp_request_url(self_p)
  result
end