How to use the h2.config.H2Configuration function in h2

To help you get started, we’ve selected a few h2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-hyper / hyper-h2 / test / test_closed_streams.py View on Github external
events = c.receive_data(window_update_frame.serialize())
        assert not events


class TestStreamsClosedByEndStream(object):
    example_request_headers = [
        (':authority', 'example.com'),
        (':path', '/'),
        (':scheme', 'https'),
        (':method', 'GET'),
    ]
    example_response_headers = [
        (':status', '200'),
        ('server', 'fake-serv/0.1.0')
    ]
    server_config = h2.config.H2Configuration(client_side=False)

    @pytest.mark.parametrize(
        "frame",
        [
            lambda self, ff: ff.build_data_frame(b'hello'),
            lambda self, ff: ff.build_headers_frame(
                self.example_request_headers, flags=['END_STREAM']),
            lambda self, ff: ff.build_headers_frame(
                self.example_request_headers),
        ]
    )
    @pytest.mark.parametrize("clear_streams", [True, False])
    def test_frames_after_recv_end_will_error(self,
                                              frame_factory,
                                              frame,
                                              clear_streams):
github python-hyper / hyper-h2 / test / test_config.py View on Github external
def test_header_encoding_must_be_false_str_none_attr(
        self, header_encoding
    ):
        """
        The value of the ``header_encoding`` setting must be False, a string,
        or None via attribute setter.
        """
        config = h2.config.H2Configuration()
        with pytest.raises(ValueError):
            config.header_encoding = header_encoding
github python-hyper / hyper-h2 / test / test_basic_logic.py View on Github external
def test_cookies_arent_joined_without_normalization(self, frame_factory):
        """
        If inbound header normalization is disabled, cookie headers aren't
        joined.
        """
        # This is a moderately varied set of cookie headers: some combined,
        # some split.
        cookie_headers = [
            ('cookie',
                'username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC'),
            ('cookie', 'path=1'),
            ('cookie', 'test1=val1; test2=val2')
        ]

        config = h2.config.H2Configuration(
            client_side=False,
            normalize_inbound_headers=False,
            header_encoding='utf-8'
        )
        c = h2.connection.H2Connection(config=config)
        c.initiate_connection()
        c.receive_data(frame_factory.preamble())

        f = frame_factory.build_headers_frame(
            self.example_request_headers + cookie_headers
        )
        events = c.receive_data(f.serialize())

        assert len(events) == 1
        e = events[0]
github facebookexperimental / doh-proxy / dohproxy / proxy.py View on Github external
def __init__(self, upstream_resolver=None, upstream_port=None,
                 uri=None, logger=None, debug=False):
        config = H2Configuration(client_side=False, header_encoding='utf-8')
        self.conn = H2Connection(config=config)
        self.logger = logger
        if logger is None:
            self.logger = utils.configure_logger('doh-proxy', 'DEBUG')
        self.transport = None
        self.debug = debug
        self.stream_data = {}
        self.upstream_resolver = upstream_resolver
        self.upstream_port = upstream_port
        self.time_stamp = 0
        self.uri = constants.DOH_URI if uri is None else uri
        assert upstream_resolver is not None, \
            'An upstream resolver must be provided'
        assert upstream_port is not None, \
            'An upstream resolver port must be provided'
github JeffBelgum / curious / curious / connection.py View on Github external
def __init__(self, socket):
        super().__init__(socket)

        h2_config = h2.config.H2Configuration(client_side=False, header_encoding='utf-8')
        self._conn = h2.connection.H2Connection(h2_config)
        self.h2_flow_control_events = {}
github encode / httpx / httpx / dispatch / http2.py View on Github external
ConcurrencyBackend,
    lookup_backend,
)
from ..config import Timeout
from ..content_streams import AsyncIteratorStream
from ..exceptions import ProtocolError
from ..models import Request, Response
from ..utils import get_logger
from .base import OpenConnection

logger = get_logger(__name__)


class HTTP2Connection(OpenConnection):
    READ_NUM_BYTES = 4096
    CONFIG = H2Configuration(validate_inbound_headers=False)

    def __init__(
        self,
        socket: BaseSocketStream,
        backend: typing.Union[str, ConcurrencyBackend] = "auto",
        on_release: typing.Callable = None,
    ):
        self.socket = socket
        self.backend = lookup_backend(backend)
        self.on_release = on_release
        self.state = h2.connection.H2Connection(config=self.CONFIG)

        self.streams = {}  # type: typing.Dict[int, HTTP2Stream]
        self.events = {}  # type: typing.Dict[int, typing.List[h2.events.Event]]

        self.init_started = False
github python-hyper / hyper-h2 / examples / twisted / twisted-server.py View on Github external
def __init__(self, root):
        config = H2Configuration(client_side=False)
        self.conn = H2Connection(config=config)
        self.known_proto = None
        self.root = root

        self._flow_control_deferreds = {}
github standy66 / purerpc / src / purerpc / grpclib / connection.py View on Github external
def __init__(self, config: GRPCConfiguration):
        self.config = config
        self.h2_connection = h2.connection.H2Connection(h2.config.H2Configuration(client_side=config.client_side,
                                                                                  header_encoding="utf-8"))
        self.h2_connection.clear_outbound_data_buffer()
        self._set_h2_connection_local_settings()
        self.message_read_buffers = {}
github CreatCodeBuild / hyper2web / hyper2web / server.py View on Github external
def __init__(self, sock, app: abstract.AbstractApp):
        config = h2.config.H2Configuration(client_side=False, header_encoding='utf-8')
        self.sock = sock
        self.conn = h2.connection.H2Connection(config=config)

        # the Application that needs this server
        # this server runs this app
        self.http = HTTP(app=app, sock=self.sock, connection=self.conn)