MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_reverse_proxy

Function test_reverse_proxy

test/mitmproxy/proxy/layers/test_modes.py:143–171  ·  view source on GitHub ↗

Test mitmproxy in reverse proxy mode. - make sure that we connect to the right host - make sure that we respect keep_host_header - make sure that we include non-standard ports in the host header (#4280)

(tctx, keep_host_header)

Source from the content-addressed store, hash-verified

141
142@pytest.mark.parametrize("keep_host_header", [True, False])
143def test_reverse_proxy(tctx, keep_host_header):
144 """Test mitmproxy in reverse proxy mode.
145
146 - make sure that we connect to the right host
147 - make sure that we respect keep_host_header
148 - make sure that we include non-standard ports in the host header (#4280)
149 """
150 server = Placeholder(Server)
151 tctx.client.proxy_mode = ProxyMode.parse("reverse:http://localhost:8000")
152 tctx.options.connection_strategy = "lazy"
153 tctx.options.keep_host_header = keep_host_header
154 assert (
155 Playbook(modes.ReverseProxy(tctx), hooks=False)
156 >> DataReceived(tctx.client, b"GET /foo HTTP/1.1\r\nHost: example.com\r\n\r\n")
157 << NextLayerHook(Placeholder(NextLayer))
158 >> reply_next_layer(lambda ctx: http.HttpLayer(ctx, HTTPMode.transparent))
159 << OpenConnection(server)
160 >> reply(None)
161 << SendData(
162 server,
163 b"GET /foo HTTP/1.1\r\n"
164 b"Host: "
165 + (b"example.com" if keep_host_header else b"localhost:8000")
166 + b"\r\n\r\n",
167 )
168 >> DataReceived(server, b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")
169 << SendData(tctx.client, b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")
170 )
171 assert server().address == ("localhost", 8000)
172
173
174def test_reverse_dns(tctx):

Callers

nothing calls this directly

Calls 9

PlaceholderFunction · 0.90
PlaybookClass · 0.90
DataReceivedClass · 0.90
NextLayerHookClass · 0.90
reply_next_layerFunction · 0.90
OpenConnectionClass · 0.90
replyClass · 0.90
SendDataClass · 0.90
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…