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

Function test_upstream_error

test/mitmproxy/proxy/layers/http/test_http3.py:614–651  ·  view source on GitHub ↗
(tctx: context.Context)

Source from the content-addressed store, hash-verified

612
613
614def test_upstream_error(tctx: context.Context):
615 playbook, cff = start_h3_proxy(tctx)
616 flow = tutils.Placeholder(HTTPFlow)
617 server = tutils.Placeholder(connection.Server)
618 err = tutils.Placeholder(bytes)
619 assert (
620 playbook
621 # request client
622 >> cff.receive_headers(example_request_headers, end_stream=True)
623 << (request := http.HttpRequestHeadersHook(flow))
624 << cff.send_decoder() # for receive_headers
625 >> tutils.reply(to=request)
626 << http.HttpRequestHook(flow)
627 >> tutils.reply()
628 # request server
629 << commands.OpenConnection(server)
630 >> tutils.reply("oops server <> error")
631 << http.HttpErrorHook(flow)
632 >> tutils.reply()
633 << cff.send_headers(
634 [
635 (b":status", b"502"),
636 (b"server", version.MITMPROXY.encode()),
637 (b"content-type", b"text/html"),
638 ]
639 )
640 << quic.SendQuicStreamData(
641 tctx.client,
642 stream_id=0,
643 data=err,
644 end_stream=True,
645 )
646 >> cff.receive_decoder() # for send_headers
647 )
648 assert cff.is_done
649 data = decode_frame(FrameType.DATA, err())
650 assert b"502 Bad Gateway" in data
651 assert b"server &lt;&gt; error" in data
652
653
654@pytest.mark.parametrize("stream", ["stream", ""])

Callers

nothing calls this directly

Calls 8

start_h3_proxyFunction · 0.85
decode_frameFunction · 0.85
receive_headersMethod · 0.80
send_decoderMethod · 0.80
receive_decoderMethod · 0.80
errFunction · 0.50
send_headersMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…