Class: Vertx::HttpClientRequest
- Inherits:
-
Object
- Object
- Vertx::HttpClientRequest
- Includes:
- WriteStream
- Defined in:
- src/main/api_shim/core/http.rb
Overview
Encapsulates a client-side HTTP request.
Instances of this class are created by an HttpClient instance, via one of the methods corresponding to the
specific HTTP methods, or the generic Vertx::HttpClient#request method.
Once an instance of this class has been obtained, headers can be set on it, and data can be written to its body,
if required. Once you are ready to send the request, the #end method must called.
Nothing is sent until the request has been internally assigned an HTTP connection. The HttpClient instance
will return an instance of this class immediately, even if there are no HTTP connections available in the pool. Any requests
sent before a connection is assigned will be queued internally and actually sent when an HTTP connection becomes
available from the pool.
The headers of the request are actually sent either when the #end method is called, or, when the first
part of the body is written, whichever occurs first.
This class supports both chunked and non-chunked HTTP.
Instance Method Summary (collapse)
-
- (Object) chunked(val = nil)
Get or set chunked.
-
- (HttpClientRequest) chunked=(val)
Sets whether the request should used HTTP chunked encoding or not.
-
- (Object) continue_handler(&hndlr)
If you send an HTTP request with the header 'Expect' set to the value '100-continue' and the server responds with an interim HTTP response with a status code of '100' and a continue handler has been set using this method, then the handler will be called.
-
- (Object) end
Ends the request.
-
- (Object) headers
MultiMap of headers for the request.
-
- (HttpClientRequest) put_header(key, value)
Inserts a header into the request.
-
- (HttpClientRequest) send_head
Forces the head of the request to be written before #end is called on the request.
-
- (Object) timeout(val = nil)
Get or set timeout.
-
- (Object) write_buffer_and_end(chunk)
Same as #end but writes some data to the response body before ending.
-
- (HttpClientRequest) write_str(str, enc = "UTF-8")
Write a [String] to the request body.
-
- (Object) write_str_and_end(str, enc = "UTF-8")
Same as #write_buffer_and_end but writes a String.
Methods included from WriteStream
#drain_handler, #exception_handler, #write, #write_queue_full?, #write_queue_max_size, #write_queue_max_size=
Instance Method Details
- (Object) chunked(val = nil)
Get or set chunked
405 406 407 408 409 410 411 412 |
# File 'src/main/api_shim/core/http.rb', line 405 def chunked(val = nil) if val @j_del.setChunked(val) self else @j_del.getChunked end end |
- (HttpClientRequest) chunked=(val)
Sets whether the request should used HTTP chunked encoding or not.
will correspond to a new HTTP chunk sent on the wire. If chunked encoding is used the HTTP header
'Transfer-Encoding' with a value of 'Chunked' will be automatically inserted in the request.
If chunked is false, this request will not use HTTP chunked encoding, and therefore if any data is written the
body of the request, the total size of that data must be set in the 'Content-Length' header before any
data is written to the request body.
399 400 401 402 |
# File 'src/main/api_shim/core/http.rb', line 399 def chunked=(val) @j_del.setChunked(val) self end |
- (Object) continue_handler(&hndlr)
If you send an HTTP request with the header 'Expect' set to the value '100-continue'
and the server responds with an interim HTTP response with a status code of '100' and a continue handler
has been set using this method, then the handler will be called.
You can then continue to write data to the request body and later end it. This is normally used in conjunction with
the #send_head method to force the request header to be written before the request has ended.
420 421 422 423 |
# File 'src/main/api_shim/core/http.rb', line 420 def continue_handler(&hndlr) @j_del.continueHandler(hndlr) self end |
- (Object) end
Ends the request. If no data has been written to the request body, and #send_head has not been called then
the actual request won't get written until this method gets called.
Once the request has ended, it cannot be used any more, and if keep alive is true the underlying connection will
be returned to the Vertx::HttpClient pool so it can be assigned to another request.
370 |
# File 'src/main/api_shim/core/http.rb', line 370 def end |
- (Object) headers
MultiMap of headers for the request
333 334 335 336 337 338 |
# File 'src/main/api_shim/core/http.rb', line 333 def headers if !@headers @headers = MultiMap.new(@j_del.headers) end @headers end |
- (HttpClientRequest) put_header(key, value)
Inserts a header into the request.
344 345 346 347 |
# File 'src/main/api_shim/core/http.rb', line 344 def put_header(key, value) @j_del.putHeader(key, value.to_s) self end |
- (HttpClientRequest) send_head
Forces the head of the request to be written before #end is called on the request. This is normally used
to implement HTTP 100-continue handling, see #continue_handler for more information.
361 362 363 364 |
# File 'src/main/api_shim/core/http.rb', line 361 def send_head @j_del.sendHead self end |
- (Object) timeout(val = nil)
Get or set timeout
426 427 428 429 430 431 432 433 |
# File 'src/main/api_shim/core/http.rb', line 426 def timeout(val = nil) if val @j_del.setTimeout(val) self else @j_del.getTimeout end end |
- (Object) write_buffer_and_end(chunk)
Same as #end but writes some data to the response body before ending. If the response is not chunked and
no other data has been written then the Content-Length header will be automatically set
386 387 388 389 |
# File 'src/main/api_shim/core/http.rb', line 386 def write_buffer_and_end(chunk) @j_del.end(chunk._to_java_buffer) self end |
- (HttpClientRequest) write_str(str, enc = "UTF-8")
Write a [String] to the request body.
353 354 355 356 |
# File 'src/main/api_shim/core/http.rb', line 353 def write_str(str, enc = "UTF-8") @j_del.write(str, enc) self end |
- (Object) write_str_and_end(str, enc = "UTF-8")
Same as #write_buffer_and_end but writes a String
378 379 380 381 |
# File 'src/main/api_shim/core/http.rb', line 378 def write_str_and_end(str, enc = "UTF-8") @j_del.end(str, enc) self end |