Class: Vertx::HttpClientRequest
- Inherits:
-
Object
- Object
- Vertx::HttpClientRequest
- Includes:
- WriteStream
- Defined in:
- lib/vertx/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
-
#chunked(val = nil) ⇒ Object
Get or set chunked.
-
#chunked=(val) ⇒ HttpClientRequest
Sets whether the request should used HTTP chunked encoding or not.
-
#continue_handler(&hndlr) ⇒ Object
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.
-
#end ⇒ Object
Ends the request.
-
#headers ⇒ Object
MultiMap of headers for the request.
-
#initialize(j_del) ⇒ HttpClientRequest
constructor
A new instance of HttpClientRequest.
-
#put_header(key, value) ⇒ HttpClientRequest
Inserts a header into the request.
-
#send_head ⇒ HttpClientRequest
Forces the head of the request to be written before #end is called on the request.
-
#timeout(val = nil) ⇒ Object
Get or set timeout.
-
#write_buffer_and_end(chunk) ⇒ Object
Same as #end but writes some data to the response body before ending.
-
#write_str(str, enc = "UTF-8") ⇒ HttpClientRequest
Write a [String] to the request body.
-
#write_str_and_end(str, enc = "UTF-8") ⇒ Object
Same as #write_buffer_and_end but writes a String.
Methods included from WriteStream
#_to_write_stream, #drain_handler, #exception_handler, #write, #write_queue_full?, #write_queue_max_size, #write_queue_max_size=
Constructor Details
#initialize(j_del) ⇒ HttpClientRequest
Returns a new instance of HttpClientRequest.
298 299 300 |
# File 'lib/vertx/http.rb', line 298 def initialize(j_del) @j_del = j_del end |
Instance Method Details
#chunked(val = nil) ⇒ Object
Get or set chunked
375 376 377 378 379 380 381 382 |
# File 'lib/vertx/http.rb', line 375 def chunked(val = nil) if val @j_del.setChunked(val) self else @j_del.getChunked end end |
#chunked=(val) ⇒ HttpClientRequest
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.
369 370 371 372 |
# File 'lib/vertx/http.rb', line 369 def chunked=(val) @j_del.setChunked(val) self end |
#continue_handler(&hndlr) ⇒ Object
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.
390 391 392 393 |
# File 'lib/vertx/http.rb', line 390 def continue_handler(&hndlr) @j_del.continueHandler(hndlr) self end |
#end ⇒ Object
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.
340 341 342 343 |
# File 'lib/vertx/http.rb', line 340 def end @j_del.end self end |
#headers ⇒ Object
MultiMap of headers for the request
303 304 305 306 307 308 |
# File 'lib/vertx/http.rb', line 303 def headers if !@headers @headers = MultiMap.new(@j_del.headers) end @headers end |
#put_header(key, value) ⇒ HttpClientRequest
Inserts a header into the request.
314 315 316 317 |
# File 'lib/vertx/http.rb', line 314 def put_header(key, value) @j_del.putHeader(key, value.to_s) self end |
#send_head ⇒ HttpClientRequest
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.
331 332 333 334 |
# File 'lib/vertx/http.rb', line 331 def send_head @j_del.sendHead self end |
#timeout(val = nil) ⇒ Object
Get or set timeout
396 397 398 399 400 401 402 403 |
# File 'lib/vertx/http.rb', line 396 def timeout(val = nil) if val @j_del.setTimeout(val) self else @j_del.getTimeout end end |
#write_buffer_and_end(chunk) ⇒ Object
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
356 357 358 359 |
# File 'lib/vertx/http.rb', line 356 def write_buffer_and_end(chunk) @j_del.end(chunk._to_java_buffer) self end |
#write_str(str, enc = "UTF-8") ⇒ HttpClientRequest
Write a [String] to the request body.
323 324 325 326 |
# File 'lib/vertx/http.rb', line 323 def write_str(str, enc = "UTF-8") @j_del.write(str, enc) self end |
#write_str_and_end(str, enc = "UTF-8") ⇒ Object
Same as #write_buffer_and_end but writes a String
348 349 350 351 |
# File 'lib/vertx/http.rb', line 348 def write_str_and_end(str, enc = "UTF-8") @j_del.end(str, enc) self end |