MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_kill_stream

Function test_kill_stream

test/mitmproxy/proxy/layers/http/test_http2.py:1009–1058  ·  view source on GitHub ↗

Test that we can kill individual streams.

(tctx)

Source from the content-addressed store, hash-verified

1007
1008
1009def test_kill_stream(tctx):
1010 """Test that we can kill individual streams."""
1011 playbook, cff = start_h2_client(tctx)
1012 flow1 = Placeholder(HTTPFlow)
1013 flow2 = Placeholder(HTTPFlow)
1014
1015 req_headers_hook_1 = http.HttpRequestHeadersHook(flow1)
1016
1017 def kill(flow: HTTPFlow):
1018 # Can't use flow.kill() here because that currently still depends on a reply object.
1019 flow.error = Error(Error.KILLED_MESSAGE)
1020
1021 server = Placeholder(Server)
1022 data_req1 = Placeholder(bytes)
1023
1024 assert (
1025 playbook
1026 >> DataReceived(
1027 tctx.client,
1028 cff.build_headers_frame(
1029 example_request_headers, flags=["END_STREAM"], stream_id=1
1030 ).serialize()
1031 + cff.build_headers_frame(
1032 example_request_headers, flags=["END_STREAM"], stream_id=3
1033 ).serialize(),
1034 )
1035 << req_headers_hook_1
1036 << http.HttpRequestHeadersHook(flow2)
1037 >> reply(side_effect=kill)
1038 << http.HttpErrorHook(flow2)
1039 >> reply()
1040 << SendData(
1041 tctx.client,
1042 cff.build_rst_stream_frame(
1043 3, error_code=ErrorCodes.INTERNAL_ERROR
1044 ).serialize(),
1045 )
1046 >> reply(to=req_headers_hook_1)
1047 << http.HttpRequestHook(flow1)
1048 >> reply()
1049 << OpenConnection(server)
1050 >> reply(None, side_effect=make_h2)
1051 << SendData(server, data_req1)
1052 )
1053 frames = decode_frames(data_req1())
1054 assert [type(x) for x in frames] == [
1055 hyperframe.frame.SettingsFrame,
1056 hyperframe.frame.WindowUpdateFrame,
1057 hyperframe.frame.HeadersFrame,
1058 ]
1059
1060
1061class TestClient:

Callers

nothing calls this directly

Calls 9

PlaceholderFunction · 0.90
DataReceivedClass · 0.90
replyClass · 0.90
SendDataClass · 0.90
OpenConnectionClass · 0.90
start_h2_clientFunction · 0.85
decode_framesFunction · 0.85
build_headers_frameMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…