Go to the latest version of this document.

# ``twisted`.`web`.`_newclient`.`HTTP11ClientProtocol``

class documentation

`class HTTP11ClientProtocol(Protocol): (source)`

Constructor: `HTTP11ClientProtocol(quiescentCallback)`

View In Hierarchy

`HTTP11ClientProtocol` is an implementation of the HTTP 1.1 client protocol. It supports as few features as possible.

Method | `__init__` | Undocumented
Method | `abort` | Close the connection and cause all outstanding `request` `Deferred`s to fire with an error.
Method | `connectionLost` | The underlying transport went away. If appropriate, notify the parser object.
Method | `connectionMade` | Called when a connection is made.
Method | `dataReceived` | Handle some stuff from some place.
Method | `request` | Issue `request` over `self.transport` and return a `Deferred` which will fire with a `Response` instance or an error.
Property | `state` | Undocumented
Method | `_connectionLost_ABORTING` | Disconnect the response parser with a `ConnectionAborted` failure, and move to the `'CONNECTION_LOST'` state.
Method | `_connectionLost_GENERATION_FAILED` | The connection was in an inconsistent state. Move to the `'CONNECTION_LOST'` state but otherwise do nothing.
Method | `_connectionLost_QUIESCENT` | Nothing is currently happening. Move to the `'CONNECTION_LOST'` state but otherwise do nothing.
Method | `_connectionLost_TRANSMITTING` | Fail the `Deferred` for the current request, notify the request object that it does not need to continue transmitting itself, and move to the `'CONNECTION_LOST'` state.
Method | `_connectionLost_TRANSMITTING_AFTER_RECEIVING_RESPONSE` | Move to the `'CONNECTION_LOST'` state.
Method | `_connectionLost_WAITING` | Disconnect the response parser so that it can propagate the event as necessary (for example, to call an application protocol's `connectionLost` method, or to fail a request `Deferred`) and move to the `'CONNECTION_LOST'`...
Method | `_disconnectParser` | If there is still a parser, call its `connectionLost` method with the given reason. If there is not, do nothing.
Method | `_finishResponse` | Called by an `HTTPClientParser` to indicate that it has parsed a complete response.
Method | `_finishResponse_WAITING` | Undocumented
Method | `_giveUp` | Lose the underlying connection and disconnect the parser with the given `Failure`.
Class Variable | `_log` | Undocumented
Instance Variable | `_abortDeferreds` | A list of `Deferred` instances that will fire when the connection is lost.
Instance Variable | `_currentRequest` | After a request is issued, the `Request` instance used to make that request. This allows `HTTP11ClientProtocol` to stop request generation if necessary (for example, if the connection is lost).
Instance Variable | `_finishedRequest` | After a request is issued, the `Deferred` which will fire when a `Response` object corresponding to that request is available. This allows `HTTP11ClientProtocol` to fail the request if there is a connection or parsing problem.
Instance Variable | `_parser` | After a request is issued, the `HTTPClientParser` to which received data making up the response to that request is delivered.
Instance Variable | `_quiescentCallback` | Undocumented
Instance Variable | `_responseDeferred` | After a request is issued, the `Deferred` from `_parser` which will fire with a `Response` when one has been received. This is eventually chained with `_finishedRequest`, but only in certain cases to avoid double firing that Deferred.
Instance Variable | `_state` | Indicates what state this `HTTP11ClientProtocol` instance is in with respect to transmission of a request and reception of a response. This may be one of the following strings:
Instance Variable | `_transportProxy` | After a request is issued, the `TransportProxyProducer` to which `_parser` is connected. This allows `_parser` to pause and resume the transport in a way which `HTTP11ClientProtocol` can exert some control over.

Inherited from `Protocol`:

Method | `logPrefix` | Return a prefix matching the class name, to identify log messages related to this protocol instance.
Class Variable | `factory` | Undocumented

Inherited from `BaseProtocol` (via `Protocol`):

Method | `makeConnection` | Make a connection to a transport and a server.
Instance Variable | `connected` | Undocumented
Instance Variable | `transport` | Undocumented

def __init__(self, quiescentCallback=lambda c: None): (source)

Undocumented

def abort(self): (source)

Close the connection and cause all outstanding `request` `Deferred`s to fire with an error.

def connectionLost(self, reason): (source)
from `twisted.internet.interfaces.IProtocol`
overrides `twisted.internet.protocol.Protocol.connectionLost`

The underlying transport went away. If appropriate, notify the parser object.

def connectionMade(self): (source)
from `twisted.internet.interfaces.IProtocol`
overrides `twisted.internet.protocol.BaseProtocol.connectionMade`

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

def dataReceived(self, bytes): (source)
from `twisted.internet.interfaces.IProtocol`
overrides `twisted.internet.protocol.Protocol.dataReceived`

Handle some stuff from some place.

def request(self, request: `Request`) -> `Deferred[IResponse]`: (source)

Issue `request` over `self.transport` and return a `Deferred` which will fire with a `Response` instance or an error.

Parameters
request:`Request` | The object defining the parameters of the request to issue.

Returns

`Deferred`

The deferred may errback with `RequestGenerationFailed` if the request was not fully written to the transport due to a local error. It may errback with `RequestTransmissionFailed` if it was not fully written to the transport due to a network error. It may errback with `ResponseFailed` if the request was sent (not necessarily received) but some or all of the response was lost. It may errback with `RequestNotSent` if it is not possible to send any more requests using this `HTTP11ClientProtocol`.

@property
state = (source)

Undocumented

def _connectionLost_ABORTING(self, reason): (source)

Disconnect the response parser with a `ConnectionAborted` failure, and move to the `'CONNECTION_LOST'` state.

def _connectionLost_GENERATION_FAILED(self, reason): (source)

The connection was in an inconsistent state. Move to the `'CONNECTION_LOST'` state but otherwise do nothing.

def _connectionLost_QUIESCENT(self, reason): (source)

Nothing is currently happening. Move to the `'CONNECTION_LOST'` state but otherwise do nothing.

def _connectionLost_TRANSMITTING(self, reason): (source)

Fail the `Deferred` for the current request, notify the request object that it does not need to continue transmitting itself, and move to the `'CONNECTION_LOST'` state.

def _connectionLost_TRANSMITTING_AFTER_RECEIVING_RESPONSE(self, reason): (source)

Move to the `'CONNECTION_LOST'` state.

def _connectionLost_WAITING(self, reason): (source)

Disconnect the response parser so that it can propagate the event as necessary (for example, to call an application protocol's `connectionLost` method, or to fail a request `Deferred`) and move to the `'CONNECTION_LOST'` state.

def _disconnectParser(self, reason): (source)

If there is still a parser, call its `connectionLost` method with the given reason. If there is not, do nothing.

Parameters
reason:`Failure` | Undocumented

def _finishResponse(self, rest: `bytes`): (source)

Called by an `HTTPClientParser` to indicate that it has parsed a complete response.

Parameters
rest:`bytes` | A `bytes` giving any trailing bytes which were given to the `HTTPClientParser` which were not part of the response it was parsing.

def _finishResponse_WAITING(self, rest: `bytes`): (source)

Undocumented

def _giveUp(self, reason): (source)

Lose the underlying connection and disconnect the parser with the given `Failure`.

Use this method instead of calling the transport's loseConnection method directly otherwise random things will break.

_log = (source)

Undocumented

_abortDeferreds: `list` = (source)

A list of `Deferred` instances that will fire when the connection is lost.

_currentRequest: `Request | None` = (source)

After a request is issued, the `Request` instance used to make that request. This allows `HTTP11ClientProtocol` to stop request generation if necessary (for example, if the connection is lost).

_finishedRequest: `Deferred[IResponse]` = (source)

After a request is issued, the `Deferred` which will fire when a `Response` object corresponding to that request is available. This allows `HTTP11ClientProtocol` to fail the request if there is a connection or parsing problem.

_parser: `HTTPClientParser | None` = (source)

After a request is issued, the `HTTPClientParser` to which received data making up the response to that request is delivered.

_quiescentCallback = (source)

Undocumented

_responseDeferred: `Deferred[IResponse] | None` = (source)

After a request is issued, the `Deferred` from `_parser` which will fire with a `Response` when one has been received. This is eventually chained with `_finishedRequest`, but only in certain cases to avoid double firing that Deferred.

_state: `str` = (source)

Indicates what state this `HTTP11ClientProtocol` instance is in with respect to transmission of a request and reception of a response. This may be one of the following strings:

- QUIESCENT: This is the state `HTTP11ClientProtocol` instances start in. Nothing is happening: no request is being sent and no response is being received or expected.
- TRANSMITTING: When a request is made (via `request`), the instance moves to this state. `Request.writeTo` has been used to start to send a request but it has not yet finished.
- TRANSMITTING_AFTER_RECEIVING_RESPONSE: The server has returned a complete response but the request has not yet been fully sent yet. The instance will remain in this state until the request is fully sent.
- GENERATION_FAILED: There was an error while the request. The request was not fully sent to the network.
- WAITING: The request was fully sent to the network. The instance is now waiting for the response to be fully received.
- ABORTING: Application code has requested that the HTTP connection be aborted.
- CONNECTION_LOST: The connection has been lost.

_transportProxy = (source)

After a request is issued, the `TransportProxyProducer` to which `_parser` is connected. This allows `_parser` to pause and resume the transport in a way which `HTTP11ClientProtocol` can exert some control over.