wsgiservlets.HTTPResponse

exception wsgiservlets.HTTPResponse(detail='')

Abstract base class for HTTP Responses.

__init__(detail='')

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:
  • detail (str or file) – default: an empty string
append(*args)

Appends each arg (converted to str) to the body.

code

The HTTP status code

content_type

The Content-Type of the response. If never explicitly set, the Content-Type will be taken from default_content_type.

default_content_type

The default Content-type, “text/html”

headers

The response headers, as a dict

set_content_type_by_filename(path)

Sets the Content-Type header based on the path extenstion.

status

The response status as string generated from code and title

title

The title of the response

wsgiservlets.http_responses_map

A mapping of HTTP status codes to HTTPResponse subclasses. I.e:

>>> http_reponses_map[404] is HTTPNotFound
True

Responses are Exceptions

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')

HTTP 1.1 Responses

Each repsonse defined in HTTP 1.1 is represented by a subclass of HTTPRepsonse. The list of responses, their code and titles:

exception wsgiservlets.HTTPContinue
  • status – 100
  • title – Continue
exception wsgiservlets.HTTPSwitchingProtocols
  • status – 101
  • title – Switching Protocols
exception wsgiservlets.HTTPOK
  • status – 200
  • title – OK
exception wsgiservlets.HTTPCreated
  • status – 201
  • title – Created
exception wsgiservlets.HTTPAccepted
  • status – 202
  • title – Accepted
exception wsgiservlets.HTTPNonAuthoritativeInformation
  • status – 203
  • title – Non-Authoritative Information
exception wsgiservlets.HTTPNoContent
  • status – 204
  • title – No Content
exception wsgiservlets.HTTPResetContent
  • status – 205
  • title – Reset Content
exception wsgiservlets.HTTPPartialContent
  • status – 206
  • title – Partial Content
exception wsgiservlets.HTTPMultipleChoices
  • status – 300
  • title – Multiple Choices
exception wsgiservlets.HTTPMovedPermanently
  • status – 301
  • title – Moved Permanently
exception wsgiservlets.HTTPFound
  • status – 302
  • title – Found
exception wsgiservlets.HTTPSeeOther
  • status – 303
  • title – See Other
exception wsgiservlets.HTTPNotModified
  • status – 304
  • title – Not Modified
exception wsgiservlets.HTTPUseProxy
  • status – 305
  • title – Use Proxy
exception wsgiservlets.HTTPUnused
  • status – 306
  • title – Unused
exception wsgiservlets.HTTPTemporaryRedirect
  • status – 307
  • title – Temporary Redirect
exception wsgiservlets.HTTPBadRequest
  • status – 400
  • title – Bad Request
exception wsgiservlets.HTTPUnauthorized
  • status – 401
  • title – Unauthorized
exception wsgiservlets.HTTPPaymentRequired
  • status – 402
  • title – Payment Required
exception wsgiservlets.HTTPForbidden
  • status – 403
  • title – Forbidden
exception wsgiservlets.HTTPNotFound
  • status – 404
  • title – Not Found
exception wsgiservlets.HTTPMethodNotAllowed
  • status – 405
  • title – Method Not Allowed
exception wsgiservlets.HTTPNotAcceptable
  • status – 406
  • title – Not Acceptable
exception wsgiservlets.HTTPProxyAuthenticationRequired
  • status – 407
  • title – Proxy Authentication Required
exception wsgiservlets.HTTPRequestTimeOut
  • status – 408
  • title – Request Time-out
exception wsgiservlets.HTTPConflict
  • status – 409
  • title – Conflict
exception wsgiservlets.HTTPGone
  • status – 410
  • title – Gone
exception wsgiservlets.HTTPLengthRequired
  • status – 411
  • title – Length Required
exception wsgiservlets.HTTPPreconditionFailed
  • status – 412
  • title – Precondition Failed
exception wsgiservlets.HTTPRequestEntityTooLarge
  • status – 413
  • title – Request Entity Too Large
exception wsgiservlets.HTTPRequestUriTooLarge
  • status – 414
  • title – Request-URI Too Large
exception wsgiservlets.HTTPUnsupportedMediaType
  • status – 415
  • title – Unsupported Media Type
exception wsgiservlets.HTTPRequestedRangeNotSatisfiable
  • status – 416
  • title – Requested Range Not Satisfiable
exception wsgiservlets.HTTPExpectationFailed
  • status – 417
  • title – Expectation Failed
exception wsgiservlets.HTTPInternalServerError
  • status – 500
  • title – Internal Server Error
exception wsgiservlets.HTTPNotImplemented
  • status – 501
  • title – Not Implemented
exception wsgiservlets.HTTPBadGateway
  • status – 502
  • title – Bad Gateway
exception wsgiservlets.HTTPServiceUnavailable
  • status – 503
  • title – Service Unavailable
exception wsgiservlets.HTTPGatewayTimeOut
  • status – 504
  • title – Gateway Time-out
exception wsgiservlets.HTTPVersionNotSupported
  • status – 505
  • title – HTTP Version not supported

Table Of Contents

Previous topic

wsgiservlets.JSONRPCServer

Next topic

wsgiservlets.Session

This Page