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 |
|
A receiver for HTTP requests. |
Class |
|
A client for HTTP 1.0. |
Class |
|
Factory for HTTP server. |
Class |
|
A HTTP request. |
Class |
|
I am a BytesIO wrapper that conforms for the transport API. I support the `writeSequence' method. |
Exception |
|
PotentialDataLoss may be raised by a transfer encoding decoder's noMoreData method to indicate that it cannot be determined if the entire response body has been delivered. This only occurs when making requests to HTTP servers which do not set ... |
Function | combined |
No summary |
Function | datetime |
Convert seconds since epoch to log datetime string. |
Function | datetime |
Convert seconds since epoch to HTTP datetime string. |
Function | from |
Convert chunk to string. |
Function | parse |
Like cgi.parse_qs, but with support for parsing byte strings on Python 3. |
Function | parse |
Parse a content-range header into (start, end, realLength). |
Function | proxied |
No summary |
Function | string |
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 |
Convert string to a chunk. |
Function | urlparse |
Parse an URL into six components. |
Constant | ACCEPTED |
Undocumented |
Constant | BAD |
Undocumented |
Constant | BAD |
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 |
Undocumented |
Constant | FORBIDDEN |
Undocumented |
Constant | FOUND |
Undocumented |
Constant | GATEWAY |
Undocumented |
Constant | GONE |
Undocumented |
Constant | H2 |
Undocumented |
Constant | HTTP |
Undocumented |
Constant | INSUFFICIENT |
Undocumented |
Constant | INTERNAL |
Undocumented |
Constant | LENGTH |
Undocumented |
Constant | MOVED |
Undocumented |
Constant | MULTI |
Undocumented |
Constant | MULTIPLE |
Undocumented |
Constant | NO |
Undocumented |
Constant | NO |
Undocumented |
Constant | NON |
Undocumented |
Constant | NOT |
Undocumented |
Constant | NOT |
Undocumented |
Constant | NOT |
Undocumented |
Constant | NOT |
Undocumented |
Constant | NOT |
Undocumented |
Constant | NOT |
Undocumented |
Constant | OK |
Undocumented |
Constant | PARTIAL |
Undocumented |
Constant | PAYMENT |
Undocumented |
Constant | PERMANENT |
Undocumented |
Constant | PRECONDITION |
Undocumented |
Constant | PROXY |
Undocumented |
Constant | REQUEST |
Undocumented |
Constant | REQUEST |
Undocumented |
Constant | REQUEST |
Undocumented |
Constant | REQUESTED |
Undocumented |
Constant | RESET |
Undocumented |
Constant | RESPONSES |
Undocumented |
Constant | SEE |
Undocumented |
Constant | SERVICE |
Undocumented |
Constant | SWITCHING |
Undocumented |
Constant | TEMPORARY |
Undocumented |
Constant | UNAUTHORIZED |
Undocumented |
Constant | UNSUPPORTED |
Undocumented |
Constant | USE |
Undocumented |
Variable | max |
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 |
Undocumented |
Variable | protocol |
Undocumented |
Variable | weekdayname |
Undocumented |
Variable | weekdayname |
Undocumented |
Interface | _ |
The interface HTTPChannel expects of Request . |
Class | _ |
Protocol for decoding chunked Transfer-Encoding, as defined by RFC 7230, section 4.1. This protocol can interpret the contents of a request or response body which uses the chunked Transfer-Encoding. ... |
Class | _ |
A proxy object that wraps one of the HTTP protocol objects, and switches between them depending on TLS negotiated protocol. |
Class | _ |
Protocol for accumulating bytes up to a specified length. This handles the case where no Transfer-Encoding is specified. |
Class | _ |
A no-op version of interfaces.IPushProducer , used to abstract over the possibility that a HTTPChannel transport does not provide IPushProducer . |
Class | _ |
IAddress which represents the client IP to log for a request, as gleaned from an X-Forwarded-For header. |
Class | _ |
Add a layer on top of another request that only uses the value of an X-Forwarded-For header as the result of getClientAddress. |
Exception | _ |
_DataLoss indicates that not all of a message body was received. This is only one of several possible exceptions which may indicate that data was lost. Because of this, it should not be checked for by specifically; any unexpected exception should be treated as having caused data loss. |
Exception | _ |
_ChunkedTransferDecoder raises _MalformedChunkedDataError from its dataReceived method when it encounters malformed data. This exception indicates a client-side error. If this exception is raised, the connection should be dropped with a 400 error. |
Function | _escape |
Return a string like python repr, but always escaped as if surrounding quotes were double quotes. |
Function | _generic |
Returns an appropriately initialized _GenericHTTPChannelProtocol. |
Function | _get |
Get a writeable file-like object to which request content can be written. |
Function | _hexint |
Decode a hexadecimal integer. |
Function | _ishexdigits |
Is the string case-insensitively hexidecimal? |
Function | _parse |
Undocumented |
Constant | _QUEUED |
Undocumented |
Constant | _REQUEST |
Undocumented |
Variable | _chunk |
Characters that are valid in a chunk extension. |
Variable | _host |
Undocumented |
Convert chunk to string.
Note that this function is not specification compliant: it doesn't handle chunk extensions.
Parameters | |
data:bytes | Undocumented |
Returns | |
Tuple[ | tuple of (result, remaining) - both bytes. |
Raises | |
ValueError | If the given data is not a correctly formatted chunked byte string. |
Like cgi.parse_qs, but with support for parsing byte strings on Python 3.
Parameters | |
qs:bytes | Undocumented |
keep | Undocumented |
strict | Undocumented |
Parse a content-range header into (start, end, realLength).
realLength might be None if real length is not known ('*').
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 |
Convert an HTTP date string (one of three formats) to seconds since epoch.
Parameters | |
date | Undocumented |
Convert string to a chunk.
Parameters | |
data:bytes | Undocumented |
Returns | |
a tuple of bytes representing the chunked encoding of data |
Parse an URL into six components.
This is similar to urlparse.urlparse, but rejects str input and always produces bytes output.
Parameters | |
url:bytes | Undocumented |
Returns | |
ParseResultBytes | The scheme, net location, path, params, query string, and fragment of the URL - all as bytes. |
Raises | |
TypeError | The given url was a str string instead of a bytes. |
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 |
|
Undocumented
Value |
|
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.
Decode a hexadecimal integer.
Unlike int(b, 16)
, this raises ValueError
when the integer has a prefix like b'0x', b'+', or b'-', which is desirable when parsing network protocols.
Is the string case-insensitively hexidecimal?
It must be composed of one or more characters in the ranges a-f, A-F and 0-9.
Characters that are valid in a chunk extension.
See RFC 7230 section 4.1.1:
chunk-ext = *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) chunk-ext-name = token chunk-ext-val = token / quoted-string
And section 3.2.6:
token = 1*tchar tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA ; any VCHAR, except delimiters quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text obs-text = %x80-FF
We don't check if chunk extensions are well-formed beyond validating that they don't contain characters outside this range.