The Web server replies the client by sending an HTTP response. It looks like this:
HTTP/1.1 200 OK
Date: Fri, 22 Jun 2007 13:03:00 GMT
Server: Apache
Last-Modified: Fri, 22 Jun 2007 13:02:32 GMT
ETag: "15c188-6-46b4ea00"
Accept-Ranges: bytes
Content-Length: 6
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/plain
Hello
Like the request, the response is split in three sections:
The status line. It is the first line, and contains the protocol version, the status code and the reason phrase.
The headers. Just like the request, the headers are a set of fields with a name and a value.
The body. And at the end, the body.
To work with the HTTP responses we have a handler too:
>>> from itools.http import Response
>>>
>>> response = Response('response.txt')
>>> print response.status
200
>>> print response.get_content_length()
6
>>> print response.body
Hello
And the programming interface:
set_header(name, value)
has_header(name)
get_header(name)
set_status(status)
get_status()
set_body(body)
redirect(location, status=302)
get_content_length()
set_cookie(name, value, **kw)
del_cookie(name)
get_cookie(name)