concurrence.http – The concurrence http module

Platforms: Unix

class concurrence.http.WSGIServer(application, request_log_level=10)

A HTTP/1.1 Web server with WSGI application interface.

Usage:

def hello_world(environ, start_response):
    start_response("200 OK", [])
    return ["<html>Hello, world!</html>"]

server = WSGIServer(hello_world)
server.serve(('localhost', 8080))

Create a new WSGIServer serving the given application. Optionally the request_log_level can be given. This loglevel is used for logging the requests.

handle_connection(socket)
All HTTP connections pass trough this method. This method provides a hook for logging, statistics and or further processing w.r.t. the connection.
handle_request(request, application)
All HTTP requests pass trough this method. This method provides a hook for logging, statistics and or further processing w.r.t. the request.
internal_server_error(environ, start_response)
Default WSGI application for creating a default 500 Internal Server Error response on any unhandled exception. The default response will render a traceback with a text/plain content-type. Can be overridden to provide a custom response.
serve(endpoint)
Serves the application at the given endpoint. The endpoint must be a tuple (<host>, <port>).
class concurrence.http.HTTPConnection

A HTTP 1.1 Client.

Usage:

#create an instance of this class and connect to a webserver using the connect method:
cnn = HTTPConnection() 
cnn.connect(('www.google.com', 80))

#create a GET request using the get method:
request = cnn.get('/index.html')

#finally perform the request to get a response:
response = cnn.perform(request)

#do something with the response:
print response.body
close()
Close this connection.
connect(endpoint)
Connect to the webserver at endpoint. endpoint is a tuple (<host>, <port>).
get(path, host=None)
Returns a new HTTPRequest with request.method = ‘GET’ and request.path = path. request.host will be set to the host used in connect(), or optionally you can specify a specific host just for this request.
perform(request)
Sends the request and waits for and returns the HTTPResult.
post(path, body=None, host=None)
Returns a new HTTPRequest with request.method = ‘POST’ and request.path = path. request.host will be set to the host used in connect(), or optionally you can specify a specific host just for this request. body is an optional string containing the data to post to the server.
receive()
Receive the next HTTPResponse from the connection.
send(request)
Sends the request on this connection.
class concurrence.http.HTTPRequest(path=None, method=None, host=None)

A class representing a HTTP request.

Create a new http request for path using method to host.

add_header(key, value)
Adds a new header to the request with name key and given value.
body
sets body data for the request
class concurrence.http.HTTPResponse

Represents a HTTP Response.

add_header(key, value)
Adds a new header to the response with name key and given value.
body
Returns the body of the response as a string.
get_header(key, default=None)
Gets the HTTP response header with the given case-insensitive key. Returns default if the header is not found.
status_code
Returns the HTTP response code as an integer.
status_reason
Returns the reason part of the HTTP response line as a string.

Previous topic

concurrence.timer – A timer module

Next topic

concurrence.database.mysql.client – The concurrence mysql driver module

This Page