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 ​Potential​Data​Loss No summary
Class ​Request A HTTP request.
Class ​String​Transport I am a BytesIO wrapper that conforms for the transport API. I support the `writeSequence' method.
Function combined​Log​Formatter
Function datetime​To​Log​String Convert seconds since epoch to log datetime string.
Function datetime​To​String Convert seconds since epoch to HTTP datetime string.
Function from​Chunk Convert chunk to string.
Function parse​_qs Like cgi.parse_qs, but with support for parsing byte strings on Python 3.
Function parse​Content​Range Parse a content-range header into (start, end, realLength).
Function proxied​Log​Formatter
Function string​To​Datetime 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 to​Chunk Convert string to a chunk.
Function urlparse Parse an URL into six components.
Constant ACCEPTED Undocumented
Constant BAD​_GATEWAY Undocumented
Constant BAD​_REQUEST Undocumented
Constant 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.
Constant CONFLICT Undocumented
Constant CREATED Undocumented
Constant EXPECTATION​_FAILED Undocumented
Constant FORBIDDEN Undocumented
Constant FOUND Undocumented
Constant GATEWAY​_TIMEOUT Undocumented
Constant GONE Undocumented
Constant H2​_ENABLED Undocumented
Constant HTTP​_VERSION​_NOT​_SUPPORTED Undocumented
Constant INSUFFICIENT​_STORAGE​_SPACE Undocumented
Constant INTERNAL​_SERVER​_ERROR Undocumented
Constant LENGTH​_REQUIRED Undocumented
Constant MOVED​_PERMANENTLY Undocumented
Constant MULTI​_STATUS Undocumented
Constant MULTIPLE​_CHOICE Undocumented
Constant NO​_BODY​_CODES Undocumented
Constant NO​_CONTENT Undocumented
Constant NON​_AUTHORITATIVE​_INFORMATION Undocumented
Constant NOT​_ACCEPTABLE Undocumented
Constant NOT​_ALLOWED Undocumented
Constant NOT​_EXTENDED Undocumented
Constant NOT​_FOUND Undocumented
Constant NOT​_IMPLEMENTED Undocumented
Constant NOT​_MODIFIED Undocumented
Constant OK Undocumented
Constant PARTIAL​_CONTENT Undocumented
Constant PAYMENT​_REQUIRED Undocumented
Constant PERMANENT​_REDIRECT Undocumented
Constant PRECONDITION​_FAILED Undocumented
Constant PROXY​_AUTH​_REQUIRED Undocumented
Constant REQUEST​_ENTITY​_TOO​_LARGE Undocumented
Constant REQUEST​_TIMEOUT Undocumented
Constant REQUEST​_URI​_TOO​_LONG Undocumented
Constant REQUESTED​_RANGE​_NOT​_SATISFIABLE Undocumented
Constant RESET​_CONTENT Undocumented
Constant RESPONSES Undocumented
Constant SEE​_OTHER Undocumented
Constant SERVICE​_UNAVAILABLE Undocumented
Constant SWITCHING Undocumented
Constant TEMPORARY​_REDIRECT Undocumented
Constant UNAUTHORIZED Undocumented
Constant UNSUPPORTED​_MEDIA​_TYPE Undocumented
Constant USE​_PROXY Undocumented
Variable monthname Undocumented
Variable monthname​_lower Undocumented
Variable protocol​_version Undocumented
Variable weekdayname Undocumented
Variable weekdayname​_lower Undocumented
Interface _​IDeprecated​HTTPChannel​To​Request​Interface The interface HTTPChannel expects of Request.
Class _​Chunked​Transfer​Decoder No summary
Class _​Data​Loss No summary
Class _​Generic​HTTPChannel​Protocol A proxy object that wraps one of the HTTP protocol objects, and switches between them depending on TLS negotiated protocol.
Class _​Identity​Transfer​Decoder Protocol for accumulating bytes up to a specified length. This handles the case where no Transfer-Encoding is specified.
Class _​Malformed​Chunked​Data​Error No summary
Class _​No​Push​Producer A no-op version of interfaces.IPushProducer, used to abstract over the possibility that a HTTPChannel transport does not provide IPushProducer.
Class _​XForwarded​For​Address IAddress which represents the client IP to log for a request, as gleaned from an X-Forwarded-For header.
Class _​XForwarded​For​Request 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 _generic​HTTPChannel​Protocol​Factory Returns an appropriately initialized _GenericHTTPChannelProtocol.
Function _get​Content​File Get a writeable file-like object to which request content can be written.
Function _parse​Header Undocumented
Constant _QUEUED​_SENTINEL Undocumented
Constant _REQUEST​_TIMEOUT Undocumented
Variable _host​Header​Expression 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
date​String: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

Value
202
BAD_GATEWAY: int = (source)

Undocumented

Value
502
BAD_REQUEST: int = (source)

Undocumented

Value
400
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.
Value
'''Magic constant returned by http.Request methods to set cache
validation headers when the request is conditional and the value fails
the condition.'''
CONFLICT: int = (source)

Undocumented

Value
409
CREATED: int = (source)

Undocumented

Value
201
EXPECTATION_FAILED: int = (source)

Undocumented

Value
417
FORBIDDEN: int = (source)

Undocumented

Value
403
FOUND: int = (source)

Undocumented

Value
302
GATEWAY_TIMEOUT: int = (source)

Undocumented

Value
504
GONE: int = (source)

Undocumented

Value
410
H2_ENABLED: bool = (source)

Undocumented

Value
False
HTTP_VERSION_NOT_SUPPORTED: int = (source)

Undocumented

Value
505
INSUFFICIENT_STORAGE_SPACE: int = (source)

Undocumented

Value
507
INTERNAL_SERVER_ERROR: int = (source)

Undocumented

Value
500
LENGTH_REQUIRED: int = (source)

Undocumented

Value
411
MOVED_PERMANENTLY: int = (source)

Undocumented

Value
301
MULTI_STATUS: int = (source)

Undocumented

Value
207
MULTIPLE_CHOICE: int = (source)

Undocumented

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

Undocumented

Value
(204, 304)
NO_CONTENT: int = (source)

Undocumented

Value
204
NON_AUTHORITATIVE_INFORMATION: int = (source)

Undocumented

Value
203
NOT_ACCEPTABLE: int = (source)

Undocumented

Value
406
NOT_ALLOWED: int = (source)

Undocumented

Value
405
NOT_EXTENDED: int = (source)

Undocumented

Value
510
NOT_FOUND: int = (source)

Undocumented

Value
404
NOT_IMPLEMENTED: int = (source)

Undocumented

Value
501
NOT_MODIFIED: int = (source)

Undocumented

Value
304

Undocumented

Value
200
PARTIAL_CONTENT: int = (source)

Undocumented

Value
206
PAYMENT_REQUIRED: int = (source)

Undocumented

Value
402
PERMANENT_REDIRECT: int = (source)

Undocumented

Value
308
PRECONDITION_FAILED: int = (source)

Undocumented

Value
412
PROXY_AUTH_REQUIRED: int = (source)

Undocumented

Value
407
REQUEST_ENTITY_TOO_LARGE: int = (source)

Undocumented

Value
413
REQUEST_TIMEOUT: int = (source)

Undocumented

Value
408
REQUEST_URI_TOO_LONG: int = (source)

Undocumented

Value
414
REQUESTED_RANGE_NOT_SATISFIABLE: int = (source)

Undocumented

Value
416
RESET_CONTENT: int = (source)

Undocumented

Value
205
RESPONSES = (source)

Undocumented

Value
{_CONTINUE: b'Continue',
 SWITCHING: b'Switching Protocols',
 OK: b'OK',
 CREATED: b'Created',
 ACCEPTED: b'Accepted',
 NON_AUTHORITATIVE_INFORMATION: b'Non-Authoritative Information',
 NO_CONTENT: b'No Content',
...
SEE_OTHER: int = (source)

Undocumented

Value
303
SERVICE_UNAVAILABLE: int = (source)

Undocumented

Value
503
SWITCHING: int = (source)

Undocumented

Value
101
TEMPORARY_REDIRECT: int = (source)

Undocumented

Value
307
UNAUTHORIZED: int = (source)

Undocumented

Value
401
UNSUPPORTED_MEDIA_TYPE: int = (source)

Undocumented

Value
415
USE_PROXY: int = (source)

Undocumented

Value
305
monthname: list = (source)

Undocumented

monthname_lower = (source)

Undocumented

protocol_version: str = (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

_QUEUED_SENTINEL = (source)

Undocumented

Value
object()
_REQUEST_TIMEOUT = (source)

Undocumented

Value
1*60
_hostHeaderExpression = (source)

Undocumented