Implements interfaces: twisted.internet.interfaces.IConsumer, twisted.internet.interfaces.IPushProducer, twisted.internet.interfaces.ITransport

A class representing a single HTTP/2 stream.

This class works hand-in-hand with H2Connection. It acts to provide an implementation of ITransport, IConsumer, and IProducer that work for a single HTTP/2 connection, while tightly cleaving to the interface provided by those interfaces. It does this by having a tight coupling to H2Connection, which allows associating many of the functions of ITransport, IConsumer, and IProducer to objects on a stream-specific level.

Instance Variable streamID The numerical stream ID that this object corresponds to. (type: int)
Instance Variable producing Whether this stream is currently allowed to produce data to its consumer. (type: bool)
Instance Variable command The HTTP verb used on the request. (type: unicode)
Instance Variable path The HTTP path used on the request. (type: unicode)
Instance Variable producer The object producing the response, if any. (type: IProducer)
Instance Variable site The twisted.web.server.Site object this stream belongs to, if any. (type: twisted.web.server.Site)
Instance Variable factory The twisted.web.http.HTTPFactory object that constructed this stream's parent connection. (type: twisted.web.http.HTTPFactory)
Method __init__ Initialize this HTTP/2 stream.
Method receiveDataChunk No summary
Method requestComplete No summary
Method connectionLost Called by the H2Connection when a connection is lost or a stream is reset.
Method windowUpdated Called by the H2Connection when this stream's flow control window has been opened.
Method flowControlBlocked Called by the H2Connection when this stream's flow control window has been exhausted.
Method writeHeaders Called by the consumer to write headers to the stream.
Method requestDone Called by a consumer to clean up whatever permanent state is in use.
Method write Write a single chunk of data into a data frame.
Method writeSequence Write a sequence of chunks of data into data frames.
Method loseConnection Close the connection after writing all pending data.
Method abortConnection Forcefully abort the connection by sending a RstStream frame.
Method getPeer Get information about the peer.
Method getHost Similar to getPeer, but for this side of the connection.
Method isSecure Returns True if this channel is using a secure transport.
Method registerProducer Register to receive data from a producer.
Method unregisterProducer
Method stopProducing
Method pauseProducing
Method resumeProducing
Instance Variable _producerProducing Whether the producer stored in producer is currently producing data. (type: bool)
Instance Variable _inboundDataBuffer Any data that has been received from the network but has not yet been received by the consumer. (type: A collections.deque containing bytes)
Instance Variable _conn A reference to the connection this stream belongs to. (type: H2Connection)
Instance Variable _request A request object that this stream corresponds to. (type: twisted.web.iweb.IRequest)
Instance Variable _buffer A buffer containing data produced by the producer that could not be sent on the network at this time. (type: io.BytesIO)
Method _convertHeaders This method converts the HTTP/2 header set into something that looks like HTTP/1.1. In particular, it strips the 'special' headers and adds a Host: header.
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.
streamID =
The numerical stream ID that this object corresponds to. (type: int)
producing =
Whether this stream is currently allowed to produce data to its consumer. (type: bool)
command =
The HTTP verb used on the request. (type: unicode)
path =
The HTTP path used on the request. (type: unicode)
producer =
The object producing the response, if any. (type: IProducer)
site =
The twisted.web.server.Site object this stream belongs to, if any. (type: twisted.web.server.Site)
factory =
The twisted.web.http.HTTPFactory object that constructed this stream's parent connection. (type: twisted.web.http.HTTPFactory)
_producerProducing =
Whether the producer stored in producer is currently producing data. (type: bool)
_inboundDataBuffer =
Any data that has been received from the network but has not yet been received by the consumer. (type: A collections.deque containing bytes)
_conn =
A reference to the connection this stream belongs to. (type: H2Connection)
_request =
A request object that this stream corresponds to. (type: twisted.web.iweb.IRequest)
_buffer =
A buffer containing data produced by the producer that could not be sent on the network at this time. (type: io.BytesIO)
def __init__(self, streamID, connection, headers, requestFactory, site, factory): (source)

Initialize this HTTP/2 stream.

ParametersstreamIDThe numerical stream ID that this object corresponds to. (type: int)
connectionThe HTTP/2 connection this stream belongs to. (type: H2Connection)
headersThe HTTP/2 request headers. (type: A list of tuples of header name and header value, both as bytes.)
requestFactoryA function that builds appropriate request request objects. (type: A callable that returns a twisted.web.iweb.IRequest.)
siteThe twisted.web.server.Site object this stream belongs to, if any. (type: twisted.web.server.Site)
factoryThe twisted.web.http.HTTPFactory object that constructed this stream's parent connection. (type: twisted.web.http.HTTPFactory)
def _convertHeaders(self, headers): (source)

This method converts the HTTP/2 header set into something that looks like HTTP/1.1. In particular, it strips the 'special' headers and adds a Host: header.

ParametersheadersThe HTTP/2 header set. (type: A list of tuples of header name and header value, both as bytes.)
def receiveDataChunk(self, data, flowControlledLength): (source)

Called when the connection has received a chunk of data from the underlying transport. If the stream has been registered with a consumer, and is currently able to push data, immediately passes it through. Otherwise, buffers the chunk until we can start producing.

ParametersdataThe chunk of data that was received. (type: bytes)
flowControlledLengthThe total flow controlled length of this chunk, which is used when we want to re-open the window. May be different to len(data). (type: int)
def requestComplete(self): (source)

Called by the H2Connection when the all data for a request has been received. Currently, with the legacy twisted.web.http.Request object, just calls requestReceived unless the producer wants us to be quiet.

def connectionLost(self, reason): (source)

Called by the H2Connection when a connection is lost or a stream is reset.

ParametersreasonThe reason the connection was lost. (type: str)
def windowUpdated(self): (source)

Called by the H2Connection when this stream's flow control window has been opened.

def flowControlBlocked(self): (source)

Called by the H2Connection when this stream's flow control window has been exhausted.

def writeHeaders(self, version, code, reason, headers): (source)

Called by the consumer to write headers to the stream.

ParametersversionThe HTTP version. (type: bytes)
codeThe status code. (type: int)
reasonThe reason phrase. Ignored in HTTP/2. (type: bytes)
headersThe HTTP response headers.
def requestDone(self, request): (source)

Called by a consumer to clean up whatever permanent state is in use.

ParametersrequestThe request calling the method. (type: twisted.web.iweb.IRequest)
def _send100Continue(self): (source)

Sends a 100 Continue response, used to signal to clients that further processing will be performed.

def _respondToBadRequestAndDisconnect(self): (source)

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.

def write(self, data): (source)

Write a single chunk of data into a data frame.

ParametersdataThe data chunk to send. (type: bytes)
def writeSequence(self, iovec): (source)

Write a sequence of chunks of data into data frames.

ParametersiovecA sequence of chunks to send. (type: An iterable of bytes chunks.)
def loseConnection(self): (source)

Close the connection after writing all pending data.

def abortConnection(self): (source)

Forcefully abort the connection by sending a RstStream frame.

def getPeer(self): (source)

Get information about the peer.

def getHost(self): (source)

Similar to getPeer, but for this side of the connection.

def isSecure(self): (source)

Returns True if this channel is using a secure transport.

ReturnsTrue if this channel is secure. (type: bool)
def registerProducer(self, producer, streaming): (source)

Register to receive data from a producer.

This sets self to be a consumer for a producer. When this object runs out of data (as when a send(2) call on a socket succeeds in moving the last data from a userspace buffer into a kernelspace buffer), it will ask the producer to resumeProducing().

For IPullProducer providers, resumeProducing will be called once each time data is required.

For IPushProducer providers, pauseProducing will be called whenever the write buffer fills up and resumeProducing will only be called when it empties.

ParametersproducerThe producer to register. (type: IProducer provider)
streamingTrue if producer provides IPushProducer, False if producer provides IPullProducer. (type: bool)
ReturnsNone
RaisesRuntimeErrorIf a producer is already registered.
API Documentation for Twisted, generated by pydoctor at 2017-09-23 19:45:03.