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
  • status100
  • titleContinue
exception wsgiservlets.HTTPSwitchingProtocols
  • status101
  • titleSwitching Protocols
exception wsgiservlets.HTTPOK
  • status200
  • titleOK
exception wsgiservlets.HTTPCreated
  • status201
  • titleCreated
exception wsgiservlets.HTTPAccepted
  • status202
  • titleAccepted
exception wsgiservlets.HTTPNonAuthoritativeInformation
  • status203
  • titleNon-Authoritative Information
exception wsgiservlets.HTTPNoContent
  • status204
  • titleNo Content
exception wsgiservlets.HTTPResetContent
  • status205
  • titleReset Content
exception wsgiservlets.HTTPPartialContent
  • status206
  • titlePartial Content
exception wsgiservlets.HTTPMultipleChoices
  • status300
  • titleMultiple Choices
exception wsgiservlets.HTTPMovedPermanently
  • status301
  • titleMoved Permanently
exception wsgiservlets.HTTPFound
  • status302
  • titleFound
exception wsgiservlets.HTTPSeeOther
  • status303
  • titleSee Other
exception wsgiservlets.HTTPNotModified
  • status304
  • titleNot Modified
exception wsgiservlets.HTTPUseProxy
  • status305
  • titleUse Proxy
exception wsgiservlets.HTTPUnused
  • status306
  • titleUnused
exception wsgiservlets.HTTPTemporaryRedirect
  • status307
  • titleTemporary Redirect
exception wsgiservlets.HTTPBadRequest
  • status400
  • titleBad Request
exception wsgiservlets.HTTPUnauthorized
  • status401
  • titleUnauthorized
exception wsgiservlets.HTTPPaymentRequired
  • status402
  • titlePayment Required
exception wsgiservlets.HTTPForbidden
  • status403
  • titleForbidden
exception wsgiservlets.HTTPNotFound
  • status404
  • titleNot Found
exception wsgiservlets.HTTPMethodNotAllowed
  • status405
  • titleMethod Not Allowed
exception wsgiservlets.HTTPNotAcceptable
  • status406
  • titleNot Acceptable
exception wsgiservlets.HTTPProxyAuthenticationRequired
  • status407
  • titleProxy Authentication Required
exception wsgiservlets.HTTPRequestTimeOut
  • status408
  • titleRequest Time-out
exception wsgiservlets.HTTPConflict
  • status409
  • titleConflict
exception wsgiservlets.HTTPGone
  • status410
  • titleGone
exception wsgiservlets.HTTPLengthRequired
  • status411
  • titleLength Required
exception wsgiservlets.HTTPPreconditionFailed
  • status412
  • titlePrecondition Failed
exception wsgiservlets.HTTPRequestEntityTooLarge
  • status413
  • titleRequest Entity Too Large
exception wsgiservlets.HTTPRequestUriTooLarge
  • status414
  • titleRequest-URI Too Large
exception wsgiservlets.HTTPUnsupportedMediaType
  • status415
  • titleUnsupported Media Type
exception wsgiservlets.HTTPRequestedRangeNotSatisfiable
  • status416
  • titleRequested Range Not Satisfiable
exception wsgiservlets.HTTPExpectationFailed
  • status417
  • titleExpectation Failed
exception wsgiservlets.HTTPInternalServerError
  • status500
  • titleInternal Server Error
exception wsgiservlets.HTTPNotImplemented
  • status501
  • titleNot Implemented
exception wsgiservlets.HTTPBadGateway
  • status502
  • titleBad Gateway
exception wsgiservlets.HTTPServiceUnavailable
  • status503
  • titleService Unavailable
exception wsgiservlets.HTTPGatewayTimeOut
  • status504
  • titleGateway Time-out
exception wsgiservlets.HTTPVersionNotSupported
  • status505
  • titleHTTP Version not supported

Table Of Contents

Previous topic

wsgiservlets.JSONRPCServer

Next topic

wsgiservlets.Session

This Page