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

Function test_https_proxy

test/mitmproxy/proxy/layers/http/test_http.py:68–122  ·  view source on GitHub ↗

Test a CONNECT request, followed by a HTTP GET /

(strategy, http_connect_send_host_header, tctx)

Source from the content-addressed store, hash-verified

66@pytest.mark.parametrize("strategy", ["lazy", "eager"])
67@pytest.mark.parametrize("http_connect_send_host_header", [True, False])
68def test_https_proxy(strategy, http_connect_send_host_header, tctx):
69 """Test a CONNECT request, followed by a HTTP GET /"""
70 server = Placeholder(Server)
71 flow = Placeholder(HTTPFlow)
72 playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular))
73 tctx.options.connection_strategy = strategy
74 tctx.options.http_connect_send_host_header = http_connect_send_host_header
75
76 (
77 playbook
78 >> DataReceived(
79 tctx.client,
80 b"CONNECT example.proxy:80 HTTP/1.1"
81 + (b"\r\nHost: example.com:80" if http_connect_send_host_header else b"")
82 + b"\r\n\r\n",
83 )
84 << http.HttpConnectHook(Placeholder())
85 >> reply()
86 )
87 if strategy == "eager":
88 playbook << OpenConnection(server)
89 playbook >> reply(None)
90 (
91 playbook
92 << http.HttpConnectedHook(Placeholder())
93 >> reply(None)
94 << SendData(tctx.client, b"HTTP/1.1 200 Connection established\r\n\r\n")
95 >> DataReceived(
96 tctx.client, b"GET /foo?hello=1 HTTP/1.1\r\nHost: example.com\r\n\r\n"
97 )
98 << layer.NextLayerHook(Placeholder())
99 >> reply_next_layer(lambda ctx: http.HttpLayer(ctx, HTTPMode.transparent))
100 << http.HttpRequestHeadersHook(flow)
101 >> reply()
102 << http.HttpRequestHook(flow)
103 >> reply()
104 )
105 if strategy == "lazy":
106 playbook << OpenConnection(server)
107 playbook >> reply(None)
108 (
109 playbook
110 << SendData(server, b"GET /foo?hello=1 HTTP/1.1\r\nHost: example.com\r\n\r\n")
111 >> DataReceived(
112 server, b"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World!"
113 )
114 << http.HttpResponseHeadersHook(flow)
115 >> reply()
116 << http.HttpResponseHook(flow)
117 >> reply()
118 << SendData(
119 tctx.client, b"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World!"
120 )
121 )
122 assert playbook
123
124
125@pytest.mark.parametrize("https_client", [False, True])

Callers

nothing calls this directly

Calls 7

PlaceholderFunction · 0.90
PlaybookClass · 0.90
DataReceivedClass · 0.90
replyClass · 0.90
OpenConnectionClass · 0.90
SendDataClass · 0.90
reply_next_layerFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…