Package core :: Module http :: Class HttpClient
[hide private]
[frames] | no frames]

Class HttpClient

source code

            object --+    
                     |    
ssl_support.SSLSupport --+
                         |
            object --+   |
                     |   |
tcp_support.TCPSupport --+
                         |
                object --+
                         |
                        HttpClient

An HTTP client. A client maintains a pool of connections to a specific host, at a specific port. The HTTP connections can act as pipelines for HTTP requests. It is used as a factory for HttpClientRequest instances which encapsulate the actual HTTP requests. It is also used as a factory for HTML5 WebSocket websockets.

Instance Methods [hide private]
 
__init__(self, **kwargs) source code
 
exception_handler(self, handler)
Set the exception handler.
source code
 
get_max_pool_size(self)
The maxium number of connections this client will pool.
source code
 
set_max_pool_size(self, val)
Set the maximum pool size.
source code
 
set_keep_alive(self, val)
If val is true then, after the request has ended the connection will be returned to the pool where it can be used by another request.
source code
 
set_trust_all(self, val)
Should the client trust ALL server certificates?
source code
 
set_port(self, val)
Set the port that the client will attempt to connect to on the server on.
source code
 
set_host(self, val)
Set the host name or ip address that the client will attempt to connect to on the server on.
source code
 
connect_web_socket(self, uri, handler)
Attempt to connect an HTML5 websocket to the specified URI.
source code
 
get_now(self, uri, handler, **headers)
This is a quick version of the get method where you do not want to do anything with the request before sing.
source code
 
options(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP OPTIONS request with the specified uri.
source code
 
get(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP GET request with the specified uri.
source code
 
head(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP HEAD request with the specified uri.
source code
 
post(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP POST request with the specified uri.
source code
 
put(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP PUT request with the specified uri.
source code
 
delete(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP DELETE request with the specified uri.
source code
 
trace(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP TRACE request with the specified uri.
source code
 
connect(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP CONNECT request with the specified uri.
source code
 
patch(self, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP PATCH request with the specified uri.
source code
 
request(self, method, uri, handler)
This method returns an HttpClientRequest instance which represents an HTTP request with the specified method and uri.
source code
 
close(self)
Close the client.
source code

Inherited from ssl_support.SSLSupport: set_key_store_password, set_key_store_path, set_ssl, set_trust_store_password, set_trust_store_path

Inherited from tcp_support.TCPSupport: set_receive_buffer_size, set_reuse_address, set_send_buffer_size, set_so_linger, set_tcp_keep_alive, set_traffic_class

Class Variables [hide private]
  max_pool_size = property(get_max_pool_size, set_max_pool_size)
  keep_alive = property(fset= set_keep_alive)
  trust_all = property(fset= set_trust_all)
  port = property(fset= set_port)
  host = property(fset= set_host)

Inherited from ssl_support.SSLSupport: key_store_password, key_store_path, ssl, trust_store_password, trust_store_path

Inherited from tcp_support.TCPSupport: receive_buffer_size, reuse_address, send_buffer_size, so_linger, tcp_keep_alive, traffic_class

Method Details [hide private]

__init__(self, **kwargs)
(Constructor)

source code 
Overrides: object.__init__
(inherited documentation)

exception_handler(self, handler)

source code 

Set the exception handler.

Keyword arguments:

Parameters:
  • handler - function to be used as the handler

set_max_pool_size(self, val)

source code 

Set the maximum pool size. The client will maintain up to this number of HTTP connections in an internal pool

Keyword arguments:

Parameters:
  • val - The maximum number of connections (default to 1).

set_keep_alive(self, val)

source code 

If val is true then, after the request has ended the connection will be returned to the pool where it can be used by another request. In this manner, many HTTP requests can be pipe-lined over an HTTP connection. Keep alive connections will not be closed until the close method is invoked. If val is false then a new connection will be created for each request and it won't ever go in the pool, the connection will closed after the response has been received. Even with no keep alive, the client will not allow more than max_pool_size connections to be created at any one time.

Keyword arguments:

Parameters:
  • val - The value to use for keep_alive

set_trust_all(self, val)

source code 

Should the client trust ALL server certificates?

Keyword arguments:

Parameters:
  • val - If val is set to true then the client will trust ALL server certificates and will not attempt to authenticate them against it's local client trust store. The default value is false. Use this method with caution!

set_port(self, val)

source code 

Set the port that the client will attempt to connect to on the server on. The default value is 80

Keyword arguments:

Parameters:
  • val - The port value.

set_host(self, val)

source code 

Set the host name or ip address that the client will attempt to connect to on the server on.

Keyword arguments:

Parameters:
  • val - The host name or ip address to connect to.

connect_web_socket(self, uri, handler)

source code 

Attempt to connect an HTML5 websocket to the specified URI. The connect is done asynchronously and the handler is called with a WebSocket on success.

Keyword arguments:

Parameters:
  • uri - A relative URI where to connect the websocket on the host, e.g. /some/path
  • handler - The handler to be called with the WebSocket

get_now(self, uri, handler, **headers)

source code 

This is a quick version of the get method where you do not want to do anything with the request before sing. With this method the request is immediately sent. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the GET on the server.
  • handler - The handler to be called with the HttpClientResponse
  • headers - A dictionary of headers to pass with the request.

options(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP OPTIONS request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the OPTIONS on the server.
  • handler - The handler to be called with the HttpClientResponse

get(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP GET request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the GET on the server.
  • handler - The handler to be called with the HttpClientResponse

head(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP HEAD request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the HEAD on the server.
  • handler - The handler to be called with the HttpClientResponse

post(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP POST request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the POST on the server.
  • handler - The handler to be called with the HttpClientResponse

put(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP PUT request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the PUT on the server.
  • handler - The handler to be called with the HttpClientResponse

delete(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP DELETE request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the DELETE on the server.
  • handler - The handler to be called with the HttpClientResponse

trace(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP TRACE request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the TRACE on the server. handler. The handler to be called with the HttpClientResponse

connect(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP CONNECT request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the CONNECT on the server.
  • handler - The handler to be called with the HttpClientResponse

patch(self, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP PATCH request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the PATCH on the server.
  • handler - The handler to be called with the HttpClientResponse

request(self, method, uri, handler)

source code 

This method returns an HttpClientRequest instance which represents an HTTP request with the specified method and uri. When an HTTP response is received from the server the handler is called passing in the response. method. The HTTP method. Can be one of OPTIONS, HEAD, GET, POST, PUT, DELETE, TRACE, CONNECT.

Keyword arguments:

Parameters:
  • uri - A relative URI where to perform the OPTIONS on the server.
  • handler - The handler to be called with the HttpClientResponse

close(self)

source code 

Close the client. Any unclosed connections will be closed.