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

Function test_kill_stream

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

Test that we can kill individual streams.

(tctx: context.Context)

Source from the content-addressed store, hash-verified

964
965
966def test_kill_stream(tctx: context.Context):
967 """Test that we can kill individual streams."""
968 playbook, cff = start_h3_proxy(tctx)
969 flow1 = tutils.Placeholder(HTTPFlow)
970 flow2 = tutils.Placeholder(HTTPFlow)
971 server = tutils.Placeholder(connection.Server)
972 sff = FrameFactory(server, is_client=False)
973 headers1 = [*example_request_headers, (b"x-order", b"1")]
974 headers2 = [*example_request_headers, (b"x-order", b"2")]
975
976 def kill(flow: HTTPFlow):
977 # Can't use flow.kill() here because that currently still depends on a reply object.
978 flow.error = Error(Error.KILLED_MESSAGE)
979
980 assert (
981 playbook
982 # request client
983 >> cff.receive_headers(headers1, stream_id=0, end_stream=True)
984 << (request_header1 := http.HttpRequestHeadersHook(flow1))
985 << cff.send_decoder() # for receive_headers
986 >> cff.receive_headers(headers2, stream_id=4, end_stream=True)
987 << (request_header2 := http.HttpRequestHeadersHook(flow2))
988 << cff.send_decoder() # for receive_headers
989 >> tutils.reply(to=request_header2, side_effect=kill)
990 << http.HttpErrorHook(flow2)
991 >> tutils.reply()
992 << cff.send_reset(ErrorCode.H3_INTERNAL_ERROR, stream_id=4)
993 << cff.send_stop(ErrorCode.H3_INTERNAL_ERROR, stream_id=4)
994 >> tutils.reply(to=request_header1)
995 << http.HttpRequestHook(flow1)
996 >> tutils.reply()
997 # request server
998 << commands.OpenConnection(server)
999 >> tutils.reply(None, side_effect=make_h3)
1000 << sff.send_init()
1001 << sff.send_headers(headers1, stream_id=0, end_stream=True)
1002 >> sff.receive_init()
1003 << sff.send_encoder()
1004 >> sff.receive_encoder()
1005 >> sff.receive_decoder() # for send_headers
1006 )
1007 assert cff.is_done and sff.is_done
1008
1009
1010@pytest.mark.parametrize("close_type", ["RESET_STREAM", "STOP_SENDING"])

Callers

nothing calls this directly

Calls 12

send_initMethod · 0.95
send_headersMethod · 0.95
receive_initMethod · 0.95
send_encoderMethod · 0.95
receive_encoderMethod · 0.95
receive_decoderMethod · 0.95
start_h3_proxyFunction · 0.85
receive_headersMethod · 0.80
send_decoderMethod · 0.80
send_resetMethod · 0.80
send_stopMethod · 0.80
FrameFactoryClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…