Class: VertxWebClient::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb

Overview

A client-side HTTP request.

Instances are created by an WebClient instance, via one of the methods corresponding to the specific HTTP methods such as WebClient#get, etc...

The request shall be configured prior sending, the request is immutable and when a mutator method is called, a new request is returned allowing to expose the request in a public API and apply further customization.

After the request has been configured, the methods

can be called. The sendXXX methods perform the actual request, they can be called multiple times to perform the same HTTP request at different points in time.

The handler is called back with

  • an HttpResponse instance when the HTTP response has been received
  • a failure when the HTTP request failed (like a connection error) or when the HTTP response could not be obtained (like connection or unmarshalling errors)

Most of the time, this client will buffer the HTTP response fully unless a specific is used such as .

Instance Method Summary (collapse)

Instance Method Details

- (self) add_query_param(paramName = nil, paramValue = nil)

Add a query parameter to the request.

Parameters:

  • paramName (String) (defaults to: nil)
    the param name
  • paramValue (String) (defaults to: nil)
    the param value

Returns:

  • (self)

Raises:

  • (ArgumentError)

226
227
228
229
230
231
232
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 226

def add_query_param(paramName=nil,paramValue=nil)
  if paramName.class == String && paramValue.class == String && !block_given?
    @j_del.java_method(:addQueryParam, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(paramName,paramValue)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling add_query_param(#{paramName},#{paramValue})"
end

- (::VertxWebClient::HttpRequest) as(responseCodec = nil)

Configure the request to decode the response with the responseCodec.

Parameters:

Returns:

Raises:

  • (ArgumentError)

85
86
87
88
89
90
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 85

def as(responseCodec=nil)
  if responseCodec.class.method_defined?(:j_del) && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:as, [Java::IoVertxExtWebCodec::BodyCodec.java_class]).call(responseCodec.j_del),::VertxWebClient::HttpRequest, nil)
  end
  raise ArgumentError, "Invalid arguments when calling as(#{responseCodec})"
end

- (self) basicAuthentication(id, password) - (self) basicAuthentication(id, password)

Configure the request to perform basic access authentication.

In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic <credentials>', where credentials is the base64 encoding of id and password joined by a colon.

Overloads:

  • - (self) basicAuthentication(id, password)

    Parameters:

    • id (String)
      the id
    • password (String)
      the password
  • - (self) basicAuthentication(id, password)

    Parameters:

Returns:

  • (self)

Raises:

  • (ArgumentError)

176
177
178
179
180
181
182
183
184
185
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 176

def basic_authentication(param_1=nil,param_2=nil)
  if param_1.class == String && param_2.class == String && !block_given?
    @j_del.java_method(:basicAuthentication, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(param_1,param_2)
    return self
  elsif param_1.class.method_defined?(:j_del) && param_2.class.method_defined?(:j_del) && !block_given?
    @j_del.java_method(:basicAuthentication, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del,param_2.j_del)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling basic_authentication(#{param_1},#{param_2})"
end

- (self) bearer_token_authentication(bearerToken = nil)

Configure the request to perform bearer token authentication.

In OAuth 2.0, a request contains a header field of the form 'Authorization: Bearer <bearerToken>', where bearerToken is the bearer token issued by an authorization server to access protected resources.

Parameters:

  • bearerToken (String) (defaults to: nil)
    the bearer token

Returns:

  • (self)

Raises:

  • (ArgumentError)

193
194
195
196
197
198
199
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 193

def bearer_token_authentication(bearerToken=nil)
  if bearerToken.class == String && !block_given?
    @j_del.java_method(:bearerTokenAuthentication, [Java::java.lang.String.java_class]).call(bearerToken)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling bearer_token_authentication(#{bearerToken})"
end

- (::VertxWebClient::HttpRequest) copy

Copy this request

Returns:

Raises:

  • (ArgumentError)

282
283
284
285
286
287
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 282

def copy
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:copy, []).call(),::VertxWebClient::HttpRequest, nil)
  end
  raise ArgumentError, "Invalid arguments when calling copy()"
end

- (self) expect(predicate) { ... } - (self) expect(predicate)

Add an expectation that the response is valid according to the provided predicate.

Multiple predicates can be added.

Overloads:

Returns:

  • (self)

Raises:

  • (ArgumentError)

262
263
264
265
266
267
268
269
270
271
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 262

def expect(param_1=nil)
  if block_given? && param_1 == nil
    @j_del.java_method(:expect, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWebClient::HttpResponse, nil)).j_del }))
    return self
  elsif param_1.class.method_defined?(:j_del) && !block_given?
    @j_del.java_method(:expect, [Java::IoVertxExtWebClientPredicate::ResponsePredicate.java_class]).call(param_1.j_del)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling expect(#{param_1})"
end

- (self) follow_redirects(value = nil)

Set wether or not to follow the directs for the request.

Parameters:

  • value (true, false) (defaults to: nil)
    true if redirections should be followed

Returns:

  • (self)

Raises:

  • (ArgumentError)

247
248
249
250
251
252
253
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 247

def follow_redirects(value=nil)
  if (value.class == TrueClass || value.class == FalseClass) && !block_given?
    @j_del.java_method(:followRedirects, [Java::boolean.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling follow_redirects(#{value})"
end

- (::Vertx::MultiMap) headers

Returns The HTTP headers

Returns:

Raises:

  • (ArgumentError)

155
156
157
158
159
160
161
162
163
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 155

def headers
  if !block_given?
    if @cached_headers != nil
      return @cached_headers
    end
    return @cached_headers = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:headers, []).call(),::Vertx::MultiMap)
  end
  raise ArgumentError, "Invalid arguments when calling headers()"
end

- (self) host(value = nil)

Configure the request to use a new host value.

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

94
95
96
97
98
99
100
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 94

def host(value=nil)
  if value.class == String && !block_given?
    @j_del.java_method(:host, [Java::java.lang.String.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling host(#{value})"
end

- (self) method(value = nil)

Configure the request to use a new method value.

Parameters:

  • value (:OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT, :PATCH, :OTHER) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

55
56
57
58
59
60
61
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 55

def method(value=nil)
  if value.class == Symbol && !block_given?
    @j_del.java_method(:method, [Java::IoVertxCoreHttp::HttpMethod.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(value.to_s))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling method(#{value})"
end

- (::VertxWebClient::HttpRequest) multipart_mixed(allow = nil)

Allow or disallow multipart mixed encoding when sending having files sharing the same file name.
The default value is true.
Set to false if you want to achieve the behavior for HTML5.

Parameters:

  • allow (true, false) (defaults to: nil)
    true allows use of multipart mixed encoding

Returns:

Raises:

  • (ArgumentError)

296
297
298
299
300
301
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 296

def multipart_mixed(allow=nil)
  if (allow.class == TrueClass || allow.class == FalseClass) && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:multipartMixed, [Java::boolean.java_class]).call(allow),::VertxWebClient::HttpRequest, nil)
  end
  raise ArgumentError, "Invalid arguments when calling multipart_mixed(#{allow})"
end

- (self) port(value = nil)

Configure the request to use a new port value.

Parameters:

  • value (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

75
76
77
78
79
80
81
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 75

def port(value=nil)
  if value.class == Fixnum && !block_given?
    @j_del.java_method(:port, [Java::int.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling port(#{value})"
end

- (self) put_header(name = nil, value = nil)

Configure the request to set a new HTTP header.

Parameters:

  • name (String) (defaults to: nil)
    the header name
  • value (String) (defaults to: nil)
    the header value

Returns:

  • (self)

Raises:

  • (ArgumentError)

147
148
149
150
151
152
153
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 147

def put_header(name=nil,value=nil)
  if name.class == String && value.class == String && !block_given?
    @j_del.java_method(:putHeader, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(name,value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling put_header(#{name},#{value})"
end

- (self) put_headers(headers = nil)

Configure the request to add multiple HTTP headers .

Parameters:

Returns:

  • (self)

Raises:

  • (ArgumentError)

136
137
138
139
140
141
142
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 136

def put_headers(headers=nil)
  if headers.class.method_defined?(:j_del) && !block_given?
    @j_del.java_method(:putHeaders, [Java::IoVertxCore::MultiMap.java_class]).call(headers.j_del)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling put_headers(#{headers})"
end

- (::Vertx::MultiMap) query_params

Return the current query parameters.

Returns:

Raises:

  • (ArgumentError)

274
275
276
277
278
279
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 274

def query_params
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:queryParams, []).call(),::Vertx::MultiMap)
  end
  raise ArgumentError, "Invalid arguments when calling query_params()"
end

- (self) raw_method(method = nil)

Configure the request to use a custom HTTP method

Parameters:

  • method (String) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

65
66
67
68
69
70
71
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 65

def raw_method(method=nil)
  if method.class == String && !block_given?
    @j_del.java_method(:rawMethod, [Java::java.lang.String.java_class]).call(method)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling raw_method(#{method})"
end

- (void) send { ... }

This method returns an undefined value.

Send a request, the handler will receive the response as an VertxWebClient::HttpResponse.

Yields:

Raises:

  • (ArgumentError)

371
372
373
374
375
376
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 371

def send
  if block_given?
    return @j_del.java_method(:send, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send()"
end

- (void) send_buffer(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body buffer.

Parameters:

Yields:

Raises:

  • (ArgumentError)

316
317
318
319
320
321
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 316

def send_buffer(body=nil)
  if body.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:sendBuffer, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoVertxCore::Handler.java_class]).call(body.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_buffer(#{body})"
end

- (void) send_form(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body multimap encoded as form and the content type set to application/x-www-form-urlencoded.

When the content type header is previously set to multipart/form-data it will be used instead.

Parameters:

Yields:

Raises:

  • (ArgumentError)

351
352
353
354
355
356
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 351

def send_form(body=nil)
  if body.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:sendForm, [Java::IoVertxCore::MultiMap.java_class,Java::IoVertxCore::Handler.java_class]).call(body.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_form(#{body})"
end

- (void) send_json(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body object encoded as json and the content type set to application/json.

Parameters:

  • body (Object) (defaults to: nil)
    the body

Yields:

Raises:

  • (ArgumentError)

338
339
340
341
342
343
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 338

def send_json(body=nil)
  if ::Vertx::Util::unknown_type.accept?(body) && block_given?
    return @j_del.java_method(:sendJson, [Java::java.lang.Object.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_object(body),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_json(#{body})"
end

- (void) send_json_object(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body object encoded as json and the content type set to application/json.

Parameters:

  • body (Hash{String => Object}) (defaults to: nil)
    the body

Yields:

Raises:

  • (ArgumentError)

327
328
329
330
331
332
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 327

def send_json_object(body=nil)
  if body.class == Hash && block_given?
    return @j_del.java_method(:sendJsonObject, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_json_object(body),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_json_object(#{body})"
end

- (void) send_multipart_form(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body multimap encoded as form and the content type set to multipart/form-data. You may use this method to send attributes and upload files.

Parameters:

Yields:

Raises:

  • (ArgumentError)

362
363
364
365
366
367
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 362

def send_multipart_form(body=nil)
  if body.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:sendMultipartForm, [Java::IoVertxExtWebMultipart::MultipartForm.java_class,Java::IoVertxCore::Handler.java_class]).call(body.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_multipart_form(#{body})"
end

- (void) send_stream(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body stream.

Parameters:

Yields:

Raises:

  • (ArgumentError)

306
307
308
309
310
311
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 306

def send_stream(body=nil)
  if body.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:sendStream, [Java::IoVertxCoreStreams::ReadStream.java_class,Java::IoVertxCore::Handler.java_class]).call(body.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_stream(#{body})"
end

- (self) set_query_param(paramName = nil, paramValue = nil)

Set a query parameter to the request.

Parameters:

  • paramName (String) (defaults to: nil)
    the param name
  • paramValue (String) (defaults to: nil)
    the param value

Returns:

  • (self)

Raises:

  • (ArgumentError)

237
238
239
240
241
242
243
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 237

def set_query_param(paramName=nil,paramValue=nil)
  if paramName.class == String && paramValue.class == String && !block_given?
    @j_del.java_method(:setQueryParam, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(paramName,paramValue)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_query_param(#{paramName},#{paramValue})"
end

- (self) ssl(value = nil)

Parameters:

  • value (true, false) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

202
203
204
205
206
207
208
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 202

def ssl(value=nil)
  if (value.class == TrueClass || value.class == FalseClass) && !block_given?
    @j_del.java_method(:ssl, [Java::JavaLang::Boolean.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling ssl(#{value})"
end

- (self) timeout(value = nil)

Configures the amount of time in milliseconds after which if the request does not return any data within the timeout period an TimeoutException fails the request.

Setting zero or a negative value disables the timeout.

Parameters:

  • value (Fixnum) (defaults to: nil)
    The quantity of time in milliseconds.

Returns:

  • (self)

Raises:

  • (ArgumentError)

215
216
217
218
219
220
221
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 215

def timeout(value=nil)
  if value.class == Fixnum && !block_given?
    @j_del.java_method(:timeout, [Java::long.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling timeout(#{value})"
end

- (self) uri(value = nil)

Configure the request to use a new request URI value.

When the uri has query parameters, they are set in the #query_params multimap, overwritting any parameters previously set.

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

126
127
128
129
130
131
132
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 126

def uri(value=nil)
  if value.class == String && !block_given?
    @j_del.java_method(:uri, [Java::java.lang.String.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling uri(#{value})"
end

- (self) virtual_host(value = nil)

Configure the request to use a virtual host value.

Usually the header host (:authority pseudo header for HTTP/2) is set from the request host value since this host value resolves to the server IP address.

Sometimes you need to set a host header for an address that does not resolve to the server IP address. The virtual host value overrides the value of the actual host header (:authority pseudo header for HTTP/2).

The virtual host is also be used for SNI.

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

113
114
115
116
117
118
119
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_request.rb', line 113

def virtual_host(value=nil)
  if value.class == String && !block_given?
    @j_del.java_method(:virtualHost, [Java::java.lang.String.java_class]).call(value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling virtual_host(#{value})"
end