mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
Merge pull request #3899 from mhils/dont-add-host-header
Don't force host header on outgoing requests
This commit is contained in:
commit
0b393b2878
@ -1,4 +1,3 @@
|
|||||||
import mitmproxy.net.http.url
|
|
||||||
from mitmproxy import exceptions
|
from mitmproxy import exceptions
|
||||||
|
|
||||||
|
|
||||||
@ -78,15 +77,7 @@ def _assemble_request_headers(request_data):
|
|||||||
Args:
|
Args:
|
||||||
request_data (mitmproxy.net.http.request.RequestData)
|
request_data (mitmproxy.net.http.request.RequestData)
|
||||||
"""
|
"""
|
||||||
headers = request_data.headers
|
return bytes(request_data.headers)
|
||||||
if "host" not in headers and request_data.scheme and request_data.host and request_data.port:
|
|
||||||
headers = headers.copy()
|
|
||||||
headers["host"] = mitmproxy.net.http.url.hostport(
|
|
||||||
request_data.scheme,
|
|
||||||
request_data.host,
|
|
||||||
request_data.port
|
|
||||||
)
|
|
||||||
return bytes(headers)
|
|
||||||
|
|
||||||
|
|
||||||
def _assemble_response_line(response_data):
|
def _assemble_response_line(response_data):
|
||||||
|
@ -15,7 +15,6 @@ def test_assemble_request():
|
|||||||
b"GET /path HTTP/1.1\r\n"
|
b"GET /path HTTP/1.1\r\n"
|
||||||
b"header: qvalue\r\n"
|
b"header: qvalue\r\n"
|
||||||
b"content-length: 7\r\n"
|
b"content-length: 7\r\n"
|
||||||
b"host: address:22\r\n"
|
|
||||||
b"\r\n"
|
b"\r\n"
|
||||||
b"content"
|
b"content"
|
||||||
)
|
)
|
||||||
@ -84,17 +83,6 @@ def test_assemble_request_headers():
|
|||||||
assert b"Transfer-Encoding" in c
|
assert b"Transfer-Encoding" in c
|
||||||
|
|
||||||
|
|
||||||
def test_assemble_request_headers_host_header():
|
|
||||||
r = treq()
|
|
||||||
r.headers = Headers()
|
|
||||||
c = _assemble_request_headers(r.data)
|
|
||||||
assert b"host" in c
|
|
||||||
|
|
||||||
r.host = None
|
|
||||||
c = _assemble_request_headers(r.data)
|
|
||||||
assert b"host" not in c
|
|
||||||
|
|
||||||
|
|
||||||
def test_assemble_response_headers():
|
def test_assemble_response_headers():
|
||||||
# https://github.com/mitmproxy/mitmproxy/issues/186
|
# https://github.com/mitmproxy/mitmproxy/issues/186
|
||||||
r = tresp(content=b"")
|
r = tresp(content=b"")
|
||||||
|
Loading…
Reference in New Issue
Block a user