MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / FrameFactory

Class FrameFactory

test/mitmproxy/proxy/layers/http/hyper_h2_test_helpers.py:31–172  ·  view source on GitHub ↗

A class containing lots of helper methods and state to build frames. This allows test cases to easily build correct HTTP/2 frames to feed to hyper-h2.

Source from the content-addressed store, hash-verified

29
30
31class FrameFactory:
32 """
33 A class containing lots of helper methods and state to build frames. This
34 allows test cases to easily build correct HTTP/2 frames to feed to
35 hyper-h2.
36 """
37
38 def __init__(self):
39 self.encoder = Encoder()
40
41 def refresh_encoder(self):
42 self.encoder = Encoder()
43
44 def preamble(self):
45 return b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
46
47 def build_headers_frame(self, headers, flags=[], stream_id=1, **priority_kwargs):
48 """
49 Builds a single valid headers frame out of the contained headers.
50 """
51 f = HeadersFrame(stream_id)
52 f.data = self.encoder.encode(headers)
53 f.flags.add("END_HEADERS")
54 for flag in flags:
55 f.flags.add(flag)
56
57 for k, v in priority_kwargs.items():
58 setattr(f, k, v)
59
60 return f
61
62 def build_continuation_frame(self, header_block, flags=[], stream_id=1):
63 """
64 Builds a single continuation frame out of the binary header block.
65 """
66 f = ContinuationFrame(stream_id)
67 f.data = header_block
68 f.flags = set(flags)
69
70 return f
71
72 def build_data_frame(self, data, flags=None, stream_id=1, padding_len=0):
73 """
74 Builds a single data frame out of a chunk of data.
75 """
76 flags = set(flags) if flags is not None else set()
77 f = DataFrame(stream_id)
78 f.data = data
79 f.flags = flags
80
81 if padding_len:
82 flags.add("PADDED")
83 f.pad_length = padding_len
84
85 return f
86
87 def build_settings_frame(self, settings, ack=False):
88 """

Callers 14

h2_framesFunction · 0.90
start_h2_clientFunction · 0.90
test_simpleFunction · 0.90
test_response_trailersFunction · 0.90
test_long_responseFunction · 0.90
test_no_normalizationFunction · 0.90
test_http_1_1_requiredFunction · 0.90
test_max_concurrencyFunction · 0.90
test_early_server_dataFunction · 0.90

Calls

no outgoing calls

Tested by 13

h2_framesFunction · 0.72
start_h2_clientFunction · 0.72
test_simpleFunction · 0.72
test_response_trailersFunction · 0.72
test_long_responseFunction · 0.72
test_no_normalizationFunction · 0.72
test_http_1_1_requiredFunction · 0.72
test_max_concurrencyFunction · 0.72
test_early_server_dataFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…