Package core :: Module http :: Class HttpClientRequest

[hide private]
[frames] | no frames]

# Class HttpClientRequest

source code

             object --+
                      |
    streams.WriteStream --+
                          |
                         HttpClientRequest

Instances of this class are created by an HttpClient instance, via one of the methods corresponding to the specific HTTP methods, or the generic 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 Methods | [hide private]

__init__(self, java_obj) | source code

headers(self) Hash of headers for the request | source code

put_header(self, key, value) Inserts a header into the request. | source code

write_buffer(self, chunk, handler=None) Write a to the request body. | source code

write_str(self, str, enc="UTF-8", handler=None) Write a to the request body. | source code

send_head(self) Forces the head of the request to be written before end is called on the request. | source code

end(self) Ends the request. | source code

write_str_and_end(self, str, enc="UTF-8") Same as write_buffer_and_end but writes a String | source code

write_buffer_and_end(self, chunk) Same as end but writes some data to the response body before ending. | source code

set_chunked(self, val) Sets whether the request should used HTTP chunked encoding or not. | source code

continue_handler(self, handler) 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. | source code

Inherited from `streams.WriteStream`: `drain_handler`, `exception_handler`, `set_write_queue_max_size`, `write_queue_full` Inherited from `streams.WriteStream` (private): `_to_write_stream`

Class Variables | [hide private]

| chunked = `property(fset= set_chunked)`
Inherited from `streams.WriteStream`: `write_queue_max_size`

Method Details | [hide private]

### __init__(self, java_obj)
(Constructor)

source code

Overrides: object.__init__
  (inherited documentation)

### headers(self)

source code

Hash of headers for the request

Decorators:
  - `@property`

### put_header(self, key, value)

source code

Inserts a header into the request.

Keyword arguments:

Parameters:
  - `key` - The header key
  - `value` - The header value. to_s will be called on the value to determine the actual String value to insert.
Returns:
  self so multiple operations can be chained.

### write_buffer(self, chunk, handler=None)

source code

Write a to the request body.

Keyword arguments:

Parameters:
  - `chunk` - The buffer to write.
  - `handler` - The handler will be called when the buffer has actually been written to the wire.
Returns:
  self So multiple operations can be chained.
Overrides: streams.WriteStream.write_buffer

### write_str(self, str, enc="UTF-8", handler=None)

source code

Write a to the request body.

Keyword arguments:

Parameters:
  - `str` - The string to write.
  - `enc` - The encoding to use.
  - `handler` - The handler will be called when the buffer has actually been written to the wire.
Returns:
  self So multiple operations can be chained.

### send_head(self)

source code

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.

Returns:
  self So multiple operations can be chained.

### end(self)

source code

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 HttpClient pool so it can be assigned to another request.

### write_str_and_end(self, str, enc="UTF-8")

source code

Same as write_buffer_and_end but writes a String

Keyword arguments:

Parameters:
  - `str` - The String to write
  - `enc` - The encoding

### write_buffer_and_end(self, chunk)

source code

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

Keyword arguments:

Parameters:
  - `chunk` - The Buffer to write

### set_chunked(self, val)

source code

Sets whether the request should used HTTP chunked encoding or not.

Keyword arguments:

Parameters:
  - `val` - If val is true, this request will use HTTP chunked encoding, and each call to write to the body 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.

Returns:
  self So multiple operations can be chained.

### continue_handler(self, handler)

source code

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.

Keyword arguments:

Parameters:
  - `handler` - The handler