Abstract base class for HTTP Responses.
An HTTP response is constructed by specifying, optionally, detail which becomes the body of the response. If detail is an open file object, then the response body will be the content of the file. If it is a string, a StringIO will be used as the body and will be seeded with the string. If empty (the default), an empty StringIO will be used. In the later cases (where StringIO is used), output can be appended to the body with calls to append().
Parameters: |
|
---|
Appends each arg (converted to str) to the body.
The HTTP status code
The Content-Type of the response. If never explicitly set, the Content-Type will be taken from default_content_type.
The default Content-type, “text/html”
The response headers, as a dict
Sets the Content-Type header based on the path extenstion.
The response status as string generated from code and title
The title of the response
A mapping of HTTP status codes to HTTPResponse subclasses. I.e:
>>> http_reponses_map[404] is HTTPNotFound
True
Because HTTPResponse subclasses Exception, any of these responses can be raised as an exception to abort the request. For example, if it is programmitcally determined that a resource doesn’t exist, one can write:
if cannot_find_smoke_shifter:
raise HTTPNotFound('Could not find the left-handed smoke shifter')
Each repsonse defined in HTTP 1.1 is represented by a subclass of HTTPRepsonse. The list of responses, their code and titles: