An HTTP 1.1 client.
The way to use the functionality provided by this module is to:
- Connect a
HTTP11ClientProtocol
to an HTTP server - Create a
Request
with the appropriate data - Pass the request to
HTTP11ClientProtocol.request
- The returned Deferred will fire with a
Response
object - Create a
IProtocol
provider which can handle the response body - Connect it to the response with
Response.deliverBody
- When the protocol's connectionLost method is called, the response is complete. See
Response.deliverBody
for details.
Various other classes in this module support this usage:
- HTTPParser is the basic HTTP parser. It can handle the parts of HTTP which are symmetric between requests and responses.
- HTTPClientParser extends HTTPParser to handle response-specific parts of HTTP. One instance is created for each request to parse the corresponding response.
Class |
|
Helper object which exposes IConsumer on top of HTTP11ClientProtocol for streaming request bodies to the server. |
Class |
|
HTTP11ClientProtocol is an implementation of the HTTP 1.1 client protocol. It supports as few features as possible. |
Class |
|
An HTTP parser which only handles HTTP responses. |
Class |
|
HTTPParser handles the parsing side of HTTP processing. With a suitable subclass, it can parse either the client side or the server side of the connection. |
Class |
|
An IConsumer proxy which enforces an exact length requirement on the total data written to it. |
Class |
|
A Request instance describes an HTTP request to be sent to an HTTP server. |
Class |
|
An twisted.internet.interfaces.IPushProducer implementation which wraps another such thing and proxies calls to it until it is told to stop. |
Exception |
|
Headers passed to Request were in some way invalid. |
Exception |
|
The version string in a status line was unparsable. |
Exception |
|
The connection was explicitly aborted by application code. |
Exception |
|
The body IBodyProducer for a request tried to write data after indicating it had finished writing data. |
Exception |
|
Some received data could not be parsed. |
Exception |
|
RequestNotSent indicates that an attempt was made to issue a request but for reasons unrelated to the details of the request itself, the request could not be sent. For example, this may indicate that an attempt was made to send a request using a protocol which is no longer connected to a server. |
Exception |
|
An IBodyProducer declared the number of bytes it was going to produce (via its length attribute) and then produced a different number of bytes. |
Function | make |
Given a dispatch name and a function, return a function which can be used as a method and which, when called, will call another method defined on the instance and return the result. The other method which is called is determined by the value of the ... |
Constant | BODY |
Undocumented |
Constant | DONE |
Undocumented |
Constant | HEADER |
Undocumented |
Constant | STATUS |
Undocumented |
Exception | _ |
_WrapperException is the base exception type for exceptions which include one or more other exceptions as the low-level causes. |
Function | _content |
Parse the I{Content-Length} connection header. |
Function | _ensure |
An HTTP method is an HTTP token, which consists of any visible ASCII character that is not a delimiter (i.e. one of "(),/:;<=>?@[\]{}.) |
Function | _ensure |
A valid URI cannot contain control characters (i.e., characters between 0-32, inclusive and 127) or non-ASCII characters (i.e., characters with values between 128-255, inclusive). |
Constant | _VALID |
Undocumented |
Variable | _ |
Undocumented |
Variable | _ignore |
Undocumented |
Variable | _ignore |
Undocumented |
Variable | _ignore |
Undocumented |
Variable | _module |
Undocumented |
Given a dispatch name and a function, return a function which can be used as a method and which, when called, will call another method defined on the instance and return the result. The other method which is called is determined by the value of the _state attribute of the instance.
Parameters | |
name | A string which is used to construct the name of the subsidiary method to invoke. The subsidiary method is named like '_%s_%s' % (name, _state). |
template | A function object which is used to give the returned function a docstring. |
Returns | |
The dispatcher function. |
Parse the I{Content-Length} connection header. Two forms of duplicates are permitted. Header repetition: Content-Length: 42 Content-Length: 42 And field value repetition: Content-Length: 42, 42 Duplicates are only permitted if they have the same decimal value (so C{7, 007} are also permitted). @param connHeaders: Connection headers per L{HTTPParser.connHeaders} @returns: A non-negative number of octets, or L{None} when there is no I{Content-Length} header. @raises ValueError: when there are conflicting headers, a header value isn't an integer, or a header value is negative. @see: U{https://datatracker.ietf.org/doc/html/rfc9110#section-8.6}
An HTTP method is an HTTP token, which consists of any visible ASCII character that is not a delimiter (i.e. one of "(),/:;<=>?@[\]{}.)
Parameters | |
method:bytes | the method to check |
Returns | |
bytes | the method if it is valid |
Raises | |
ValueError | if the method is not valid |
See Also | |
https://tools.ietf.org/html/rfc7230#section-3.1.1, https://tools.ietf.org/html/rfc7230#section-3.2.6, https://tools.ietf.org/html/rfc5234#appendix-B.1 |
A valid URI cannot contain control characters (i.e., characters between 0-32, inclusive and 127) or non-ASCII characters (i.e., characters with values between 128-255, inclusive).
Parameters | |
uri:bytes | the URI to check |
Returns | |
bytes | the URI if it is valid |
Raises | |
ValueError | if the URI is not valid |
See Also | |
https://tools.ietf.org/html/rfc3986#section-3.3, https://tools.ietf.org/html/rfc3986#appendix-A, https://tools.ietf.org/html/rfc5234#appendix-B.1 |