How to use the h2.settings.SettingCodes 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 mitmproxy / mitmproxy / test / mitmproxy / proxy / protocol / test_http2.py View on Github external
def setup_class(cls):
        _Http2TestBase.setup_class()
        _Http2ServerBase.setup_class(h2_server_settings={h2.settings.SettingCodes.MAX_CONCURRENT_STREAMS: 2})
github vmagamedov / grpclib / tests / test_protocol.py View on Github external
assert connection_window > initial_window_size, (
            '{} should be greater than {}'
            .format(connection_window, initial_window_size)
        )
        server_conn.increment_flow_control_window(
            connection_window - initial_window_size
        )

    if stream_window is not None:
        server_conn.update_settings({
            SettingCodes.INITIAL_WINDOW_SIZE: stream_window
        })

    if max_frame_size is not None:
        server_conn.update_settings({
            SettingCodes.MAX_FRAME_SIZE: max_frame_size
        })

    client_conn = H2Connection(H2Configuration(client_side=True,
                                               header_encoding='ascii'))
    client_conn.initiate_connection()

    client_conn.receive_data(server_conn.data_to_send())
    server_conn.receive_data(client_conn.data_to_send())
    client_conn.receive_data(server_conn.data_to_send())

    return client_conn, server_conn
github python-hyper / hyper-h2 / test / test_basic_logic.py View on Github external
The remote peer can shrink the maximum outbound frame size using
        settings.
        """
        c = h2.connection.H2Connection(config=self.server_config)
        c.initiate_connection()
        c.receive_data(frame_factory.preamble())

        f = frame_factory.build_headers_frame(self.example_request_headers)
        c.receive_data(f.serialize())
        c.clear_outbound_data_buffer()

        with pytest.raises(h2.exceptions.FrameTooLargeError):
            c.send_data(1, b'\x01' * 17000)

        received_frame = frame_factory.build_settings_frame(
            {h2.settings.SettingCodes.MAX_FRAME_SIZE: 17001}
        )
        c.receive_data(received_frame.serialize())

        c.send_data(1, b'\x01' * 17000)
        assert c.data_to_send()
github vmagamedov / grpclib / tests / test_protocol.py View on Github external
header_encoding='ascii'))
    server_conn.initiate_connection()

    if connection_window is not None:
        initial_window_size = server_conn.local_settings.initial_window_size
        assert connection_window > initial_window_size, (
            '{} should be greater than {}'
            .format(connection_window, initial_window_size)
        )
        server_conn.increment_flow_control_window(
            connection_window - initial_window_size
        )

    if stream_window is not None:
        server_conn.update_settings({
            SettingCodes.INITIAL_WINDOW_SIZE: stream_window
        })

    if max_frame_size is not None:
        server_conn.update_settings({
            SettingCodes.MAX_FRAME_SIZE: max_frame_size
        })

    client_conn = H2Connection(H2Configuration(client_side=True,
                                               header_encoding='ascii'))
    client_conn.initiate_connection()

    client_conn.receive_data(server_conn.data_to_send())
    server_conn.receive_data(client_conn.data_to_send())
    client_conn.receive_data(server_conn.data_to_send())

    return client_conn, server_conn
github python-hyper / hyper-h2 / h2 / settings.py View on Github external
def _setting_code_from_int(code):
    """
    Given an integer setting code, returns either one of :class:`SettingCodes
    ` or, if not present in the known set of codes,
    returns the integer directly.
    """
    try:
        return SettingCodes(code)
    except ValueError:
        return code
github Fatal1ty / aioapns / aioapns / connection.py View on Github external
def on_remote_settings_changed(self, changed_settings):
        for setting in changed_settings.values():
            logger.debug('Remote setting changed: %s', setting)
            if setting.setting == SettingCodes.MAX_CONCURRENT_STREAMS:
                self.free_channels.bound = setting.new_value
github pgjones / hypercorn / hypercorn / trio / h2.py View on Github external
self.config = config

        self.streams: Dict[int, H2AsyncStream] = {}
        self.flow_control: Dict[int, trio.Event] = {}
        self.send_lock = trio.Lock()
        self.upgrade_request = upgrade_request
        self.received_data = received_data

        self.connection = h2.connection.H2Connection(
            config=h2.config.H2Configuration(client_side=False, header_encoding=None)
        )
        self.connection.DEFAULT_MAX_INBOUND_FRAME_SIZE = config.h2_max_inbound_frame_size
        self.connection.local_settings = h2.settings.Settings(
            client=False,
            initial_values={
                h2.settings.SettingCodes.MAX_CONCURRENT_STREAMS: config.h2_max_concurrent_streams,
                h2.settings.SettingCodes.MAX_HEADER_LIST_SIZE: config.h2_max_header_list_size,
                h2.settings.SettingCodes.ENABLE_CONNECT_PROTOCOL: 1,
            },
github hansroh / aquests / aquests / protocols / http2 / request_handler.py View on Github external
self.asyncon = handler.asyncon
		self.request = handler.request
		base_request_handler.RequestHandler.__init__ (self, handler.request.logger)
		#self.asyncon.set_timeout (60, 60)
		self.lock = handler.asyncon.lock # pool lock
		self._ssl = handler._ssl
		
		self._clock = threading.RLock () # conn lock
		self._llock = threading.RLock () # local lock
		self.fakecon = FakeAsynConnect (self.asyncon, self.logger)		
		
		self.initiate ()		
		is_upgrade = not (self._ssl or self.request.initial_http_version == "2.0")			
		if is_upgrade:
			self.conn.initiate_upgrade_connection()
			self.conn.update_settings({SettingCodes.ENABLE_PUSH: 0})
			# assume 1st request's stream_id = 1
			self.add_request (1, handler)
			self._send_stream_id = 1 # nexet request stream_id will be 3
		else:		    
			self.conn.initiate_connection()				
			
		self.send_data ()
		self.asyncon.set_terminator (9)
		
		if not is_upgrade:			
			self.handle_request (handler)
		else:
			self.asyncon.set_active (False)
github HENNGE / aapns / src / aapns / connection.py View on Github external
# https://bugs.python.org/issue40111 validate context h2 alpn

        protocol = h2.connection.H2Connection(
            h2.config.H2Configuration(client_side=True, header_encoding="utf-8")
        )
        protocol.local_settings = h2.settings.Settings(
            client=True,
            initial_values={
                # Apple server settings:
                # HEADER_TABLE_SIZE 4096
                # MAX_CONCURRENT_STREAMS 1000
                # INITIAL_WINDOW_SIZE 65535
                # MAX_FRAME_SIZE 16384
                # MAX_HEADER_LIST_SIZE 8000
                h2.settings.SettingCodes.ENABLE_PUSH: 0,
                h2.settings.SettingCodes.MAX_CONCURRENT_STREAMS: 2 ** 20,
                h2.settings.SettingCodes.MAX_HEADER_LIST_SIZE: 2 ** 16 - 1,
                h2.settings.SettingCodes.INITIAL_WINDOW_SIZE: MAX_RESPONSE_SIZE,
            },
        )

        protocol.initiate_connection()
        protocol.increment_flow_control_window(CONNECTION_WINDOW_SIZE)

        read_stream, write_stream = await wait_for(
            open_connection(
                host, port, ssl=ssl_context, ssl_handshake_timeout=TLS_TIMEOUT
            ),
            CONNECTION_TIMEOUT,
        )
        try: