Retica Response Class¶
The Response class is used to build & parse responses.
Creating A Response¶
import Retica
response = Retica.Response.response()
Modifying The Response¶
The Response class has the following attributes:
status - The status of the response.
headers - The headers of the response.
body - The body of the response.
protocol - The protocol of the response.
content_type - The content type of the response.
connection - The connection status after the response has been received.
response.status = 200
response.headers = {'set-cookie': 'session=123456789'}
response.body = '<h1>Hello World!</h1>'
response.protocol = 'HTTP/1.1'
response.content_type = 'text/html'
response.connection = 'keep-alive'
Parsing A Response¶
An encoded string can be parsed and stored into the response object using the response.parse()
method.4
>>> response.parse('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: keep-alive\r\nSet-Cookie: session=123456789\r\n\r\n<h1>Hello World!</h1>')
>>> print(type(response))
Compiling The Response Into A String¶
The response can be compiled using the response.compile()
method.
>>> response.compile()
'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: keep-alive\r\nSet-Cookie: session=123456789\r\n\r\n<h1>Hello World!</h1>'