Halberd.clientlib.HTTPClient

Package Halberd :: Module clientlib :: Class HTTPClient |
[hide private]
[frames] | no frames]

# Class HTTPClient

source code

Known Subclasses:
  - HTTPSClient

Special-purpose HTTP client.

Instance Methods | [hide private]
__init__(self) Initializes the object. | source code
`tuple` |
getHeaders(self, address, urlstr) Talk to the target webserver and fetch MIME headers. | source code
_putRequest(self, address, urlstr) Sends an HTTP request to the target webserver. | source code
`tuple` |
_getHostAndPort(self, netloc) Determine the hostname and port to connect to from an URL | source code
`str` |
_fillTemplate(self, hostname, port, url, params=`'````'`, query=`'````'`, fragment=`'````'`) Fills the request template with relevant information. | source code
_connect(self, addr) Connect to the target address. | source code
_sendAll(self, data) Sends a string to the socket. | source code
`tuple` |
_getReply(self) Read a reply from the server. | source code
__del__(self) | source code

Instance Variables | [hide private]
`float` | timeout = `2` Timeout for socket operations (expressed in seconds).
`int` | bufsize = `1024` Buffer size for network I/O.
`str` | template = ``'``GET %(request)s HTTP/1.1\r\nHost: %(hostname)s%(po``...`` Template of the HTTP request to be sent to the target.
`callable` | _recv Reference to a callable responsible from reading data from the network.

Method Details | [hide private]

### getHeaders(self, address, urlstr) | source code
Talk to the target webserver and fetch MIME headers. Parameters: `address` (`tuple`) - The target's network address. `urlstr` (`str`) - URL to use. Returns: `tuple` The time when the client started reading the server's response and the MIME headers that were sent.

### _putRequest(self, address, urlstr) | source code
Sends an HTTP request to the target webserver. This method connects to the target server, sends the HTTP request and records a timestamp. Parameters: `address` (`str`) - Target address. `urlstr` (`str`) - A valid Unified Resource Locator. Raises: `InvalidURL` - In case the URL scheme is not HTTP or HTTPS `ConnectionRefused` - If it can't reach the target webserver. `TimedOut` - If we cannot send the data within the specified time.

### _getHostAndPort(self, netloc) | source code
Determine the hostname and port to connect to from an URL Parameters: `netloc` (`str`) - Relevant part of the parsed URL. Returns: `tuple` Hostname (`str`) and port (`int`)

### _fillTemplate(self, hostname, port, url, params=`'````'`, query=`'````'`, fragment=`'````'`) | source code
Fills the request template with relevant information. Parameters: `hostname` (`str`) - Target host to reach. `port` (`int`) - Remote port. `url` (`str`) - URL to use as source. Returns: `str` A request ready to be sent

### _connect(self, addr) | source code
Connect to the target address. Parameters: `addr` (`tuple`) - The target's address. Raises: `ConnectionRefused` - If it can't reach the target webserver.

### _getReply(self) | source code
Read a reply from the server. Returns: `tuple` Time when the data started arriving plus the received data. Raises: `UnknownReply` - If the remote server doesn't return a valid HTTP reply. `TimedOut` - In case reading from the network takes too much time.

Instance Variable Details | [hide private]

  ### timeout Timeout for socket operations (expressed in seconds). WARNING: changing this value is strongly discouraged. Type: `float` Value:
      2

  ### template Template of the HTTP request to be sent to the target. Type: `str` Value:
      '''GET %(request)s HTTP/1.1\r
      Host: %(hostname)s%(port)s\r
      Pragma: no-cache\r
      Cache-control: no-cache\r
      User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20
      050414 Firefox/1.0.3\r
      Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicati
      on/x-shockwave-flash, */*\r
      ...