Package DebTorrent :: Module HTTPHandler :: Class HTTPConnection
[hide private]
[frames] | no frames]

Class HTTPConnection

source code

A single connection from an HTTP client.

Handles a single HTTP GET or HEAD request from a client using HTTP/1.0.

Instance Methods [hide private]
 
__init__(self, handler, connection)
Initialize the instance.
source code
string
get_ip(self)
Get the IP address of the connection.
source code
boolean
data_came_in(self, data)
Process data that came in on the connection.
source code
method
read_type(self, data)
Process the first header line that came in.
source code
method
read_header(self, data)
Process the next header line that came in.
source code
 
answer(self, r, httpreq)
Add a response to the queued responses and check if any are ready to send.
source code
 
send_answer(self, (responsecode, responsestring, headers, data), header, command, path, encoding, req_headers)
Send out the complete request.
source code
 
close(self)
Close the connection and drop all pending requests/answers.
source code
Instance Variables [hide private]
string buf
the buffered data received on the connection
boolean close_connection
whether the connection will be closed after this request
boolean closed
whether the connection has been closed
string command
the requested command ('GET' or 'HEAD')
SocketHandler.SingleSocket connection
the new connection that was created
boolean done
whether the response has been sent
boolean donereading
whether the headers have been read
string encoding
the encoding to use when sending the response
HTTPHandler handler
the handler for all incoming HTTP connections
string header
the first header line received from the request
dictionary headers
the headers received with the request
method next_func
the next method to call to process data on this connection
string path
the requested path to get
string protocol
the protocol used to make the request
list of HTTPRequest requests
the outstanding requests for paths
(int, int) version
the protocol version of the request
Method Details [hide private]

__init__(self, handler, connection)
(Constructor)

source code 
Initialize the instance.
Parameters:

get_ip(self)

source code 
Get the IP address of the connection.
Returns: string
the IP address

data_came_in(self, data)

source code 

Process data that came in on the connection.

Processes the request lines one at a time by calling the next_func method with the lines.
Parameters:
  • data (string) - the data that came in
Returns: boolean
whether to keep the connection open

read_type(self, data)

source code 
Process the first header line that came in.
Parameters:
  • data (string) - the line that came in
Returns: method
the next method to call to process data on this connection

read_header(self, data)

source code 
Process the next header line that came in.
Parameters:
  • data (string) - the line that came in
Returns: method
the next method to call to process data on this connection

answer(self, r, httpreq)

source code 
Add a response to the queued responses and check if any are ready to send.
Parameters:
  • r ((int, string, dictionary, string)) - the HTTP status code, status message, headers, and package data
  • httpreq (HTTPRequest) - the request the answer is for

send_answer(self, (responsecode, responsestring, headers, data), header, command, path, encoding, req_headers)

source code 
Send out the complete request.
Parameters:
  • responsecode (int) - the response code to send
  • responsestring (string) - the response string to send
  • headers (dictionary) - the headers to send with the response
  • data (string) - the data to send with the response
  • header (string) - the first header line received from the request
  • command (string) - the requested command ('GET' or 'HEAD')
  • path (string) - the requested path to get
  • encoding (string) - the encoding to use when sending the response
  • req_headers (dictionary) - the headers received with the request