module documentation
(source)

HyperText Transfer Protocol implementation.

This is the basic server-side protocol implementation used by the Twisted Web server. It can parse HTTP 1.0 requests and supports many HTTP 1.1 features as well. Additionally, some functionality implemented here is also useful for HTTP clients (such as the chunked encoding parser).

Class HTTPChannel A receiver for HTTP requests.
Class HTTPClient A client for HTTP 1.0.
Class HTTPFactory Factory for HTTP server.
Class PotentialDataLoss No summary
Class Request A HTTP request.
Class StringTransport I am a BytesIO wrapper that conforms for the transport API. I support the `writeSequence' method.
Function combinedLogFormatter
Function datetimeToLogString Convert seconds since epoch to log datetime string.
Function datetimeToString Convert seconds since epoch to HTTP datetime string.
Function fromChunk Convert chunk to string.
Function parse_qs Like cgi.parse_qs, but with support for parsing byte strings on Python 3.
Function parseContentRange Parse a content-range header into (start, end, realLength).
Function proxiedLogFormatter
Function stringToDatetime Convert an HTTP date string (one of three formats) to seconds since epoch.
Function timegm Convert time tuple in GMT to seconds since epoch, GMT
Function toChunk Convert string to a chunk.
Function urlparse Parse an URL into six components.
Variable ACCEPTED Undocumented
Variable BAD_GATEWAY Undocumented
Variable BAD_REQUEST Undocumented
Variable CACHED A marker value to be returned from cache-related request methods to indicate to the caller that a cached response will be usable and no response body should be generated.
Variable CONFLICT Undocumented
Variable CREATED Undocumented
Variable EXPECTATION_FAILED Undocumented
Variable FORBIDDEN Undocumented
Variable FOUND Undocumented
Variable GATEWAY_TIMEOUT Undocumented
Variable GONE Undocumented
Variable H2_ENABLED Undocumented
Variable HTTP_VERSION_NOT_SUPPORTED Undocumented
Variable INSUFFICIENT_STORAGE_SPACE Undocumented
Variable INTERNAL_SERVER_ERROR Undocumented
Variable LENGTH_REQUIRED Undocumented
Variable maxChunkSizeLineLength Maximum allowable length of the CRLF-terminated line that indicates the size of a chunk and the extensions associated with it, as in the HTTP 1.1 chunked Transfer-Encoding (RFC 7230 section 4.1). This limits how much data may be buffered when decoding the line.
Variable monthname Undocumented
Variable monthname_lower Undocumented
Variable MOVED_PERMANENTLY Undocumented
Variable MULTI_STATUS Undocumented
Variable MULTIPLE_CHOICE Undocumented
Variable NO_BODY_CODES Undocumented
Variable NO_CONTENT Undocumented
Variable NON_AUTHORITATIVE_INFORMATION Undocumented
Variable NOT_ACCEPTABLE Undocumented
Variable NOT_ALLOWED Undocumented
Variable NOT_EXTENDED Undocumented
Variable NOT_FOUND Undocumented
Variable NOT_IMPLEMENTED Undocumented
Variable NOT_MODIFIED Undocumented
Variable OK Undocumented
Variable PARTIAL_CONTENT Undocumented
Variable PAYMENT_REQUIRED Undocumented
Variable PERMANENT_REDIRECT Undocumented
Variable PRECONDITION_FAILED Undocumented
Variable protocol_version Undocumented
Variable PROXY_AUTH_REQUIRED Undocumented
Variable REQUEST_ENTITY_TOO_LARGE Undocumented
Variable REQUEST_TIMEOUT Undocumented
Variable REQUEST_URI_TOO_LONG Undocumented
Variable REQUESTED_RANGE_NOT_SATISFIABLE Undocumented
Variable RESET_CONTENT Undocumented
Variable RESPONSES Undocumented
Variable SEE_OTHER Undocumented
Variable SERVICE_UNAVAILABLE Undocumented
Variable SWITCHING Undocumented
Variable TEMPORARY_REDIRECT Undocumented
Variable UNAUTHORIZED Undocumented
Variable UNSUPPORTED_MEDIA_TYPE Undocumented
Variable USE_PROXY Undocumented
Variable weekdayname Undocumented
Variable weekdayname_lower Undocumented
Interface _IDeprecatedHTTPChannelToRequestInterface The interface HTTPChannel expects of Request.
Class _ChunkedTransferDecoder No summary
Class _DataLoss No summary
Class _GenericHTTPChannelProtocol A proxy object that wraps one of the HTTP protocol objects, and switches between them depending on TLS negotiated protocol.
Class _IdentityTransferDecoder Protocol for accumulating bytes up to a specified length. This handles the case where no Transfer-Encoding is specified.
Class _MalformedChunkedDataError No summary
Class _NoPushProducer A no-op version of interfaces.IPushProducer, used to abstract over the possibility that a HTTPChannel transport does not provide IPushProducer.
Class _XForwardedForAddress IAddress which represents the client IP to log for a request, as gleaned from an X-Forwarded-For header.
Class _XForwardedForRequest Add a layer on top of another request that only uses the value of an X-Forwarded-For header as the result of getClientAddress.
Function _escape Return a string like python repr, but always escaped as if surrounding quotes were double quotes.
Function _genericHTTPChannelProtocolFactory Returns an appropriately initialized _GenericHTTPChannelProtocol.
Function _getContentFile Get a writeable file-like object to which request content can be written.
Function _parseHeader Undocumented
Variable _hostHeaderExpression Undocumented
Variable _QUEUED_SENTINEL Undocumented
Variable _REQUEST_TIMEOUT Undocumented
@provider(IAccessLogFormatter)
def combinedLogFormatter(timestamp, request): (source)
Returns
A combined log formatted log line for the given request.
See Also
IAccessLogFormatter
def datetimeToLogString(msSinceEpoch=None): (source)
Convert seconds since epoch to log datetime string.
Returns
strUndocumented
def datetimeToString(msSinceEpoch=None): (source)
Convert seconds since epoch to HTTP datetime string.
Returns
bytesUndocumented
def fromChunk(data): (source)
Convert chunk to string.
Parameters
data:bytesUndocumented
Returns
tuple of (result, remaining) - both bytes.
Raises
ValueErrorIf the given data is not a correctly formatted chunked byte string.
def parse_qs(qs, keep_blank_values=0, strict_parsing=0): (source)
Like cgi.parse_qs, but with support for parsing byte strings on Python 3.
Parameters
qs:bytesUndocumented
keep_blank_valuesUndocumented
strict_parsingUndocumented
def parseContentRange(header): (source)

Parse a content-range header into (start, end, realLength).

realLength might be None if real length is not known ('*').

@provider(IAccessLogFormatter)
def proxiedLogFormatter(timestamp, request): (source)
Returns
A combined log formatted log line for the given request but use the value of the X-Forwarded-For header as the value for the client IP address.
See Also
IAccessLogFormatter
def stringToDatetime(dateString): (source)
Convert an HTTP date string (one of three formats) to seconds since epoch.
Parameters
dateString:bytesUndocumented
def timegm(year, month, day, hour, minute, second): (source)
Convert time tuple in GMT to seconds since epoch, GMT
def toChunk(data): (source)
Convert string to a chunk.
Parameters
data:bytesUndocumented
Returns
a tuple of bytes representing the chunked encoding of data
def urlparse(url): (source)

Parse an URL into six components.

This is similar to urlparse.urlparse, but rejects str input and always produces bytes output.

Parameters
url:bytesUndocumented
Returns
ParseResultBytesThe scheme, net location, path, params, query string, and fragment of the URL - all as bytes.
Raises
TypeErrorThe given url was a str string instead of a bytes.
ACCEPTED: int = (source)

Undocumented

BAD_GATEWAY: int = (source)

Undocumented

BAD_REQUEST: int = (source)

Undocumented

CACHED: str = (source)
A marker value to be returned from cache-related request methods to indicate to the caller that a cached response will be usable and no response body should be generated.
CONFLICT: int = (source)

Undocumented

CREATED: int = (source)

Undocumented

EXPECTATION_FAILED: int = (source)

Undocumented

FORBIDDEN: int = (source)

Undocumented

FOUND: int = (source)

Undocumented

GATEWAY_TIMEOUT: int = (source)

Undocumented

GONE: int = (source)

Undocumented

H2_ENABLED: bool = (source)

Undocumented

HTTP_VERSION_NOT_SUPPORTED: int = (source)

Undocumented

INSUFFICIENT_STORAGE_SPACE: int = (source)

Undocumented

INTERNAL_SERVER_ERROR: int = (source)

Undocumented

LENGTH_REQUIRED: int = (source)

Undocumented

maxChunkSizeLineLength: int = (source)
Maximum allowable length of the CRLF-terminated line that indicates the size of a chunk and the extensions associated with it, as in the HTTP 1.1 chunked Transfer-Encoding (RFC 7230 section 4.1). This limits how much data may be buffered when decoding the line.
monthname: list = (source)

Undocumented

monthname_lower = (source)

Undocumented

MOVED_PERMANENTLY: int = (source)

Undocumented

MULTI_STATUS: int = (source)

Undocumented

MULTIPLE_CHOICE: int = (source)

Undocumented

NO_BODY_CODES: tuple[int, ...] = (source)

Undocumented

NO_CONTENT: int = (source)

Undocumented

NON_AUTHORITATIVE_INFORMATION: int = (source)

Undocumented

NOT_ACCEPTABLE: int = (source)

Undocumented

NOT_ALLOWED: int = (source)

Undocumented

NOT_EXTENDED: int = (source)

Undocumented

NOT_FOUND: int = (source)

Undocumented

NOT_IMPLEMENTED: int = (source)

Undocumented

NOT_MODIFIED: int = (source)

Undocumented

Undocumented

PARTIAL_CONTENT: int = (source)

Undocumented

PAYMENT_REQUIRED: int = (source)

Undocumented

PERMANENT_REDIRECT: int = (source)

Undocumented

PRECONDITION_FAILED: int = (source)

Undocumented

protocol_version: str = (source)

Undocumented

PROXY_AUTH_REQUIRED: int = (source)

Undocumented

REQUEST_ENTITY_TOO_LARGE: int = (source)

Undocumented

REQUEST_TIMEOUT: int = (source)

Undocumented

REQUEST_URI_TOO_LONG: int = (source)

Undocumented

REQUESTED_RANGE_NOT_SATISFIABLE: int = (source)

Undocumented

RESET_CONTENT: int = (source)

Undocumented

RESPONSES = (source)

Undocumented

SEE_OTHER: int = (source)

Undocumented

SERVICE_UNAVAILABLE: int = (source)

Undocumented

SWITCHING: int = (source)

Undocumented

TEMPORARY_REDIRECT: int = (source)

Undocumented

UNAUTHORIZED: int = (source)

Undocumented

UNSUPPORTED_MEDIA_TYPE: int = (source)

Undocumented

USE_PROXY: int = (source)

Undocumented

weekdayname: list[str] = (source)

Undocumented

weekdayname_lower = (source)

Undocumented

def _escape(s): (source)
Return a string like python repr, but always escaped as if surrounding quotes were double quotes.
Parameters
s:bytes or strThe string to escape.
Returns
strAn escaped string.
def _genericHTTPChannelProtocolFactory(self): (source)
Returns an appropriately initialized _GenericHTTPChannelProtocol.
def _getContentFile(length): (source)
Get a writeable file-like object to which request content can be written.
def _parseHeader(line): (source)

Undocumented

_hostHeaderExpression = (source)

Undocumented

_QUEUED_SENTINEL = (source)

Undocumented

_REQUEST_TIMEOUT = (source)

Undocumented