MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / FrameFactory

Class FrameFactory

test/mitmproxy/proxy/layers/http/test_http3.py:79–352  ·  view source on GitHub ↗

Helper class for generating QUIC stream events and commands.

Source from the content-addressed store, hash-verified

77
78
79class FrameFactory:
80 """Helper class for generating QUIC stream events and commands."""
81
82 def __init__(self, conn: connection.Connection, is_client: bool) -> None:
83 self.conn = conn
84 self.is_client = is_client
85 self.decoder = pylsqpack.Decoder(
86 max_table_capacity=4096,
87 blocked_streams=16,
88 )
89 self.decoder_placeholders: list[tutils.Placeholder[bytes]] = []
90 self.encoder = pylsqpack.Encoder()
91 self.encoder_placeholder: tutils.Placeholder[bytes] | None = None
92 self.peer_stream_id: dict[StreamType, int] = {}
93 self.local_stream_id: dict[StreamType, int] = {}
94
95 def get_default_stream_id(self, stream_type: StreamType, for_local: bool) -> int:
96 if stream_type == StreamType.CONTROL:
97 stream_id = 2
98 elif stream_type == StreamType.QPACK_ENCODER:
99 stream_id = 6
100 elif stream_type == StreamType.QPACK_DECODER:
101 stream_id = 10
102 else:
103 raise AssertionError(stream_type)
104 if self.is_client is not for_local:
105 stream_id = stream_id + 1
106 return stream_id
107
108 def send_stream_type(
109 self,
110 stream_type: StreamType,
111 stream_id: int | None = None,
112 ) -> quic.SendQuicStreamData:
113 assert stream_type not in self.peer_stream_id
114 if stream_id is None:
115 stream_id = self.get_default_stream_id(stream_type, for_local=False)
116 self.peer_stream_id[stream_type] = stream_id
117 return quic.SendQuicStreamData(
118 connection=self.conn,
119 stream_id=stream_id,
120 data=encode_uint_var(stream_type),
121 end_stream=False,
122 )
123
124 def receive_stream_type(
125 self,
126 stream_type: StreamType,
127 stream_id: int | None = None,
128 ) -> quic.QuicStreamDataReceived:
129 assert stream_type not in self.local_stream_id
130 if stream_id is None:
131 stream_id = self.get_default_stream_id(stream_type, for_local=True)
132 self.local_stream_id[stream_type] = stream_id
133 return quic.QuicStreamDataReceived(
134 connection=self.conn,
135 stream_id=stream_id,
136 data=encode_uint_var(stream_type),

Callers 12

start_h3_proxyFunction · 0.70
test_fail_without_headerFunction · 0.70
test_simpleFunction · 0.70
test_response_trailersFunction · 0.70
test_request_trailersFunction · 0.70
test_stream_concurrencyFunction · 0.70
test_kill_streamFunction · 0.70
test_early_server_dataFunction · 0.70

Calls

no outgoing calls

Tested by 12

start_h3_proxyFunction · 0.56
test_fail_without_headerFunction · 0.56
test_simpleFunction · 0.56
test_response_trailersFunction · 0.56
test_request_trailersFunction · 0.56
test_stream_concurrencyFunction · 0.56
test_kill_streamFunction · 0.56
test_early_server_dataFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…