Methods ¶
__init__(data, status=200, content_type="text/html", is_file_name=False, delete_file=False)
data
The object will automatically set the Content-Length
header unless
you set the Transfer-Encoding
header to chunked
.
status
The HTTP status number to respond with.
content_type
The MIME type of the response content.
is_file_name
If True
, treat the data
string as a file name, and send the
contents of the file to the client.
delete_file
If this is True
, and is_file_name
is True
, the server deletes the
file after sending it to the client. This is useful for temp files.
setHeader(header_name, header_value)
→ str
Add/change an HTTP header in the response.
headers()
→ dict
of str
to str
Returns a dictionary of all headers in the response.
Calling this method generates a new copy of the dictionary each time, so you are advised to avoid calling it more times than necessary.
statusLabel()
→ str
Return the status label of the response. An exampe label would be 200 OK
.
Calling this method generates a new copy of the string each time, so you are advised to avoid calling it more times than necessary.
body()
→ str
Returns the body of the response.
Calling this method generates a new copy of the string each time, so you are advised to avoid calling it more times than necessary.
contentLength()
→ int
Returns the current content length of the response.
isChunked()
→ bool
Returns True if the response is a chunked response.
sendHeaders(request)
→ void
request
The request the response object is generated from.
In some cases a function might want to send the response manually and skip the built in response system. An example of its use case is when using wsgi the response is sent from python.
setBody(body, content_type)
→ void
In some cases the body may change after the initial construction of the response. This allows setting the body with a custom content type.