Server

Asynchronous, event-based server

class server.Connection(sock, addr, handler)[source]

Connection object which will represent the connection between the server and client and is used to disconnect the socket when a timeout event occurs.

class server.Server(host, port, request_handler)[source]

Server

handle_accept()[source]

Accept incoming connections and initialise and request handler for each accepted incoming connection.

class server.TimeoutHandler(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]

Separated thread used to disconnect and clean up (in)active, long running connections. The connection timeout limit is set to 13 seconds. If a connection exceeds this limit, an HTTP response with status “406 Gateway timeout” is sent and the connection is closed.

Incoming request handler

class request_handler.RequestHandler(server, sock)[source]

Request handler

handle_close()[source]

On each connection closed, the measured phase statistics are flushed to the statistics log file.

parse_request(http_blob)[source]

Parse an HTTP request blob and return a slightly modified http.client.HTTPMessage instance containing WSGI’s environment values.

>>> request = """GET /kv55/57330430 HTTP/1.1
... Host: cache.govi.openov.nl
... User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Firefox/4.0
... Accept: text/html,application/xml;q=0.9,*/*;q=0.8
... Accept-Language: en-us,en;q=0.5
... Accept-Encoding: gzip, deflate
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Keep-Alive: 115
... DNT: 1
... Connection: keep-alive
... Cache-Control: max-age=0
... 
... """
>>> env = RequestHandler(object(), None).parse_request(request)
>>> for e in env.items():
...     print e
('accept-language', 'en-us,en;q=0.5')
('accept-encoding', 'gzip, deflate')
('dnt', '1')
('connection', 'keep-alive')
('keep-alive', '115')
('accept', 'text/html,application/xml;q=0.9,*/*;q=0.8')
('user-agent', 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Firefox/4.0')
('accept-charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')
('host', 'cache.govi.openov.nl')
('request_method', 'GET')
('http_host', 'cache.govi.openov.nl')
('path_info', '/kv55/57330430')
('cache-control', 'max-age=0')
process(env)[source]

Given the WGSI environment, process the environment values, initialise the target module/class and dispatch the request based on the HTTP request method (GET/POST/HEAD).

send_not_found()[source]

Send HTTP 404 (Page not found) response to the client.

send_response(response, status='200 Ok', headers=None)[source]

Send HTTP response (consisting of HTTP status, headers and HTTP response body) to the client.

send_timeout()[source]

Send HTTP 504 (Gateway Timeout) response to the client. This response is sent when a connection timeout to an internal gateway/service is reached.

Web (HTTP) request handler

class web_handler.web_handler[source]

Wrapper class used to connect functionality of RequestHandler to the requested URL module. For example, send_response() is used for sending the HTTP response (headers, status and content) to the client.

send_response(response, status='200 Ok', headers=None)[source]

Send HTTP response (consisting of headers, status and HTTP response body) to the client. This function is a wrapper of request_handler.RequestHandler.send_response().

Table Of Contents

Previous topic

Govi requests and responses

Next topic

Server logging

This Page