twisted.web._http2.H2Connection(Protocol, TimeoutMixin)class documentation
twisted.web._http2View Source (View In Hierarchy)
A class representing a single HTTP/2 connection.
This implementation of
IProtocol works hand in hand with
H2Stream. This is because we have the requirement to register multiple producers for a single HTTP/2 connection, one for each stream. The standard Twisted interfaces don't really allow for this, so instead there's a custom interface between the two objects that allows them to work hand-in-hand here.
|Instance Variable||conn||The HTTP/2 connection state machine.|
|Instance Variable||streams||A mapping of stream IDs to
|Instance Variable||priority||A HTTP/2 priority tree used to ensure that responses are prioritised appropriately.|
|Instance Variable||abortTimeout||The number of seconds to wait after we attempt to shut the transport down cleanly to give up and forcibly terminate it. This is only used when we time a connection out, to prevent errors causing the FD to get leaked. If this is
|Method||connectionMade||Called by the reactor when a connection is received. May also be called by the
|Method||dataReceived||Called whenever a chunk of data is received from the transport.|
|Method||connectionLost||Called when the transport connection is lost.|
|Method||stopProducing||Stop producing data.|
|Method||pauseProducing||Pause producing data.|
|Method||resumeProducing||Resume producing data.|
|Method||writeDataToStream||May be called by
|Method||remainingOutboundWindow||Called to determine how much room is left in the send window for a given stream. Allows us to handle blocking and unblocking producers.|
|Method||getPeer||Get the remote address of this connection.|
|Method||getHost||Similar to getPeer, but returns an address describing this side of the connection.|
|Method||openStreamWindow||Open the stream window by a given increment.|
|Instance Variable||_consumerBlocked||A flag tracking whether or not the
|Instance Variable||_outboundStreamQueues||A map of stream IDs to queues, used to store data blocks that are yet to be sent on the connection. These are used both to handle producers that do not respect
|Instance Variable||_sender||A handle to the data-sending loop, allowing it to be terminated if needed.|
|Method||_sendPrioritisedData||The data sending loop. This function repeatedly calls itself, either from
|Method||_requestReceived||Internal handler for when a request has been received.|
|Method||_requestDataReceived||Internal handler for when a chunk of data is received for a given request.|
|Method||_requestEnded||Internal handler for when a request is complete, and we expect no further data for that request.|
|Method||_requestAborted||Internal handler for when a request is aborted by a remote peer.|
|Method||_handlePriorityUpdate||Internal handler for when a stream priority is updated.|
|Method||_requestDone||Called internally by the data sending loop to clean up state that was being used for the stream. Called when the stream is complete.|
|Method||_handleWindowUpdate||Manage flow control windows.|
|Method||_send100Continue||Sends a 100 Continue response, used to signal to clients that further processing will be performed.|
|Method||_respondToBadRequestAndDisconnect||This is a quick and dirty way of responding to bad requests.|
|Method||_streamIsActive||Checks whether Twisted has still got state for a given stream and so can process events for that stream.|
|Method||_tryToWriteControlData||Checks whether the connection is blocked on flow control and, if it isn't, writes any buffered control data.|
|Method||_flushBufferedControlData||Called when the connection is marked writable again after being marked unwritable. Attempts to flush buffered control data if there is any.|
Inherited from Protocol:
|Method||logPrefix||Return a prefix matching the class name, to identify log messages related to this protocol instance.|
|Method||makeConnection||Make a connection to a transport and a server.|
Inherited from TimeoutMixin:
|Instance Variable||timeOut||The number of seconds after which to timeout the connection.|
|Method||resetTimeout||Reset the timeout count down.|
|Method||setTimeout||Change the timeout period|
Deferredused to restart the data-sending loop when more response data has been produced. Will not be present if there is outstanding data still to send.
IConsumerbut also to allow priority to multiplex data appropriately.
intstream IDs to
collections.dequequeues, which contain either
Called by the reactor when a connection is received. May also be called by the
twisted.web.http._GenericHTTPChannelProtocol during upgrade to HTTP/2.
Called when the connection has been inactive for
self.timeOut seconds. Cleanly tears the connection down, attempting to notify the peer if needed.
We override this method to add two extra bits of functionality:
abortTimeout seconds have passed since the timeout fired, and the connection still hasn't gone away. This can really only happen on extremely bad connections or when clients are maliciously attempting to keep connections open.
Called when the transport connection is lost.
Informs all outstanding response handlers that the connection has been lost, and cleans up all internal state.
|_cancelTimeouts||Propagate the |
This function sends data on streams according to the rules of HTTP/2 priority. It ensures that the data from each stream is interleved according to the priority signalled by the client, making sure that the connection is used with maximal efficiency.
This function will execute if data is available: if all data is exhausted, the function will place a deferred onto the
H2Connection object and wait until it is called to resume executing.
Internal handler for when a request has been received.
|Parameters||event||The Hyper-h2 event that encodes information about the received request. (type: |
Internal handler for when a chunk of data is received for a given request.
|Parameters||event||The Hyper-h2 event that encodes information about the received data. (type: |
Internal handler for when a request is complete, and we expect no further data for that request.
|Parameters||event||The Hyper-h2 event that encodes information about the completed stream. (type: |
Internal handler for when a request is aborted by a remote peer.
|Parameters||event||The Hyper-h2 event that encodes information about the reset stream. (type: |
Internal handler for when a stream priority is updated.
|Parameters||event||The Hyper-h2 event that encodes information about the stream reprioritization. (type: |
twisted.web.http.Request objects to write a complete set of HTTP headers to a stream.
|Parameters||version||The HTTP version in use. Unused in HTTP/2. (type: |
|code||The HTTP status code to write. (type: |
|reason||The HTTP reason phrase to write. Unused in HTTP/2. (type: |
|headers||The headers to write to the stream. (type: |
|streamID||The ID of the stream to write the headers to. (type: |
Called internally by the data sending loop to clean up state that was being used for the stream. Called when the stream is complete.
|Parameters||streamID||The ID of the stream to clean up state for. (type: |
Called to determine how much room is left in the send window for a given stream. Allows us to handle blocking and unblocking producers.
|Parameters||streamID||The ID of the stream whose flow control window we'll check. (type: |
|Returns||The amount of room remaining in the send window for the given stream, including the data queued to be sent. (type: |
Manage flow control windows.
Streams that are blocked on flow control will register themselves with the connection. This will fire deferreds that wake those streams up and allow them to continue processing.
|Parameters||event||The Hyper-h2 event that encodes information about the flow control window change. (type: |
Get the remote address of this connection.
Treat this method with caution. It is the unfortunate result of the CGI and Jabber standards, but should not be considered reliable for the usual host of reasons; port forwarding, proxying, firewalls, IP masquerading, etc.
Similar to getPeer, but returns an address describing this side of the connection.
Sends a 100 Continue response, used to signal to clients that further processing will be performed.
|Parameters||streamID||The ID of the stream that needs the 100 Continue response (type: |
This is a quick and dirty way of responding to bad requests.
As described by HTTP standard we should be patient and accept the whole request from the client before sending a polite bad request response, even in the case when clients send tons of data.
Unlike in the HTTP/1.1 case, this does not actually disconnect the underlying transport: there's no need. This instead just sends a 400 response and terminates the stream.
|Parameters||streamID||The ID of the stream that needs the 100 Continue response (type: |
Called when the connection is marked writable again after being marked unwritable. Attempts to flush buffered control data if there is any.