Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`web`.`_http2`.`H2Stream``

class documentation

`class H2Stream: (source)`

Constructor: `H2Stream(streamID, connection, headers, requestFactory, ...)`

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

View In Hierarchy

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.

Method | `__init__` | Initialize this HTTP/2 stream.
Method | `abortConnection` | Forcefully abort the connection by sending a RstStream frame.
Method | `connectionLost` | Called by the `H2Connection` when a connection is lost or a stream is reset.
Method | `flowControlBlocked` | Called by the `H2Connection` when this stream's flow control window has been exhausted.
Method | `getHost` | Similar to getPeer, but for this side of the connection.
Method | `getPeer` | Get information about the peer.
Method | `isSecure` | Returns `True` if this channel is using a secure transport.
Method | `loseConnection` | Close the connection after writing all pending data.
Method | `pauseProducing` | No summary
Method | `receiveDataChunk` | 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...
Method | `registerProducer` | Register to receive data from a producer.
Method | `requestComplete` | 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.
Method | `requestDone` | Called by a consumer to clean up whatever permanent state is in use.
Method | `resumeProducing` | No summary
Method | `stopProducing` | No summary
Method | `unregisterProducer` | No summary
Method | `windowUpdated` | Called by the `H2Connection` when this stream's flow control window has been opened.
Method | `write` | Write a single chunk of data into a data frame.
Method | `writeHeaders` | Called by the consumer to write headers to the stream.
Method | `writeSequence` | Write a sequence of chunks of data into data frames.
Class Variable | `transport` | Undocumented
Instance Variable | `command` | The HTTP verb used on the request.
Instance Variable | `factory` | The `twisted.web.http.HTTPFactory` object that constructed this stream's parent connection.
Instance Variable | `hasStreamingProducer` | Undocumented
Instance Variable | `path` | The HTTP path used on the request.
Instance Variable | `producer` | The object producing the response, if any.
Instance Variable | `producing` | Whether this stream is currently allowed to produce data to its consumer.
Instance Variable | `site` | The `twisted.web.server.Site` object this stream belongs to, if any.
Instance Variable | `streamID` | The numerical stream ID that this object corresponds to.
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 | `_respondToBadRequestAndDisconnect` | This is a quick and dirty way of responding to bad requests.
Method | `_send100Continue` | Sends a 100 Continue response, used to signal to clients that further processing will be performed.
Instance Variable | `_buffer` | A buffer containing data produced by the producer that could not be sent on the network at this time.
Instance Variable | `_conn` | A reference to the connection this stream belongs to.
Instance Variable | `_hasStreamingProducer` | Undocumented
Instance Variable | `_inboundDataBuffer` | Any data that has been received from the network but has not yet been received by the consumer.
Instance Variable | `_producerProducing` | Whether the producer stored in producer is currently producing data.
Instance Variable | `_request` | A request object that this stream corresponds to.

def __init__(self, streamID, connection, headers, requestFactory, site, factory): (source)

Initialize this HTTP/2 stream.

Parameters
streamID:`int` | The numerical stream ID that this object corresponds to.
connection:`H2Connection` | The HTTP/2 connection this stream belongs to.
headers:A `list` of `tuple`s of header name and header value, both as `bytes`. | The HTTP/2 request headers.
requestFactory:A callable that returns a `twisted.web.iweb.IRequest`. | A function that builds appropriate request request objects.
site:`twisted.web.server.Site` | The `twisted.web.server.Site` object this stream belongs to, if any.
factory:`twisted.web.http.HTTPFactory` | The `twisted.web.http.HTTPFactory` object that constructed this stream's parent connection.

def abortConnection(self): (source)

Forcefully abort the connection by sending a RstStream frame.

def connectionLost(self, reason): (source)

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

Parameters
reason:`str` | The reason the connection was lost.

def flowControlBlocked(self): (source)

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

def getHost(self): (source)
from `twisted.internet.interfaces.ITransport`

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

def getPeer(self): (source)
from `twisted.internet.interfaces.ITransport`

Get information about the peer.

def isSecure(self): (source)

Returns `True` if this channel is using a secure transport.

Returns
`bool` | `True` if this channel is secure.

def loseConnection(self): (source)
from `twisted.internet.interfaces.ITransport`

Close the connection after writing all pending data.

def pauseProducing(self): (source)
from `twisted.internet.interfaces.IPushProducer`

See Also
`IPushProducer.pauseProducing`

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.

Parameters
data:`bytes` | The chunk of data that was received.
flowControlledLength:`int` | The total flow controlled length of this chunk, which is used when we want to re-open the window. May be different to `len(data)`.

def registerProducer(self, producer, streaming): (source)
from `twisted.internet.interfaces.IConsumer`

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.

Parameters
producer:`IProducer` provider | The producer to register.
streaming:`bool` | `True` if `producer` provides `IPushProducer`, `False` if `producer` provides `IPullProducer`.
Returns
`None`
Raises
`RuntimeError` | If a producer is already registered.

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 requestDone(self, request): (source)

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

Parameters
request:`twisted.web.iweb.IRequest` | The request calling the method.

def resumeProducing(self): (source)
from `twisted.internet.interfaces.IPushProducer`

See Also
`IPushProducer.resumeProducing`

def stopProducing(self): (source)
from `twisted.internet.interfaces.IProducer`

See Also
`IProducer.stopProducing`

def unregisterProducer(self): (source)
from `twisted.internet.interfaces.IConsumer`

See Also
`IConsumer.unregisterProducer`

def windowUpdated(self): (source)

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

def write(self, data): (source)
from `twisted.internet.interfaces.ITransport`

Write a single chunk of data into a data frame.

Parameters
data:`bytes` | The data chunk to send.

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

Called by the consumer to write headers to the stream.

Parameters
version:`bytes` | The HTTP version.
code:`int` | The status code.
reason:`bytes` | The reason phrase. Ignored in HTTP/2.
headers:Any iterable of two-tuples of `bytes`, representing header names and header values. | The HTTP response headers.

def writeSequence(self, iovec): (source)
from `twisted.internet.interfaces.ITransport`

Write a sequence of chunks of data into data frames.

Parameters
iovec:An iterable of `bytes` chunks. | A sequence of chunks to send.

transport = (source)

Undocumented

command: `unicode` = (source)

The HTTP verb used on the request.

factory: `twisted.web.http.HTTPFactory` = (source)

The `twisted.web.http.HTTPFactory` object that constructed this stream's parent connection.

hasStreamingProducer = (source)

Undocumented

path: `unicode` = (source)

The HTTP path used on the request.

producer: `IProducer` = (source)

The object producing the response, if any.

producing: `bool` = (source)

Whether this stream is currently allowed to produce data to its consumer.

site: `twisted.web.server.Site` = (source)

The `twisted.web.server.Site` object this stream belongs to, if any.

streamID: `int` = (source)

The numerical stream ID that this object corresponds to.

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.

Parameters
headers:A `list` of `tuple`s of header name and header value, both as `bytes`. | The HTTP/2 header set.

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 _send100Continue(self): (source)

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

_buffer: `io.BytesIO` = (source)

A buffer containing data produced by the producer that could not be sent on the network at this time.

_conn: `H2Connection` = (source)

A reference to the connection this stream belongs to.

_hasStreamingProducer = (source)

Undocumented

_inboundDataBuffer: A `collections.deque` containing `bytes` = (source)

Any data that has been received from the network but has not yet been received by the consumer.

_producerProducing: `bool` = (source)

Whether the producer stored in producer is currently producing data.

_request: `twisted.web.iweb.IRequest` = (source)

A request object that this stream corresponds to.