diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2017-02-18 12:08:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-18 12:08:54 +0100 |
| commit | 4158a1ae555a44661bc7128308086a624bc56d70 (patch) | |
| tree | 7b6c39321cc22db35270cb83e0ab9f04f5aef93d /test | |
| parent | 6ef4f094b3e9abf904c796779e816b89efc9fe80 (diff) | |
| parent | b9e31f213faa0607ca95841a5e9cd19b135a557f (diff) | |
| download | mitmproxy-4158a1ae555a44661bc7128308086a624bc56d70.tar.gz mitmproxy-4158a1ae555a44661bc7128308086a624bc56d70.tar.bz2 mitmproxy-4158a1ae555a44661bc7128308086a624bc56d70.zip | |
Merge pull request #2040 from mhils/request-host-header
Add "Request.host_header"
Diffstat (limited to 'test')
| -rw-r--r-- | test/mitmproxy/net/http/test_request.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/test/mitmproxy/net/http/test_request.py b/test/mitmproxy/net/http/test_request.py index 6fe57010..90ec31fe 100644 --- a/test/mitmproxy/net/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -97,7 +97,7 @@ class TestRequestCore: request.host = d assert request.data.host == b"foo\xFF\x00bar" - def test_host_header_update(self): + def test_host_update_also_updates_header(self): request = treq() assert "host" not in request.headers request.host = "example.com" @@ -107,6 +107,51 @@ class TestRequestCore: request.host = "example.org" assert request.headers["Host"] == "example.org" + def test_get_host_header(self): + no_hdr = treq() + assert no_hdr.host_header is None + + h1 = treq(headers=( + (b"host", b"example.com"), + )) + assert h1.host_header == "example.com" + + h2 = treq(headers=( + (b":authority", b"example.org"), + )) + assert h2.host_header == "example.org" + + both_hdrs = treq(headers=( + (b"host", b"example.org"), + (b":authority", b"example.com"), + )) + assert both_hdrs.host_header == "example.com" + + def test_modify_host_header(self): + h1 = treq() + assert "host" not in h1.headers + assert ":authority" not in h1.headers + h1.host_header = "example.com" + assert "host" in h1.headers + assert ":authority" not in h1.headers + h1.host_header = None + assert "host" not in h1.headers + + h2 = treq(http_version=b"HTTP/2.0") + h2.host_header = "example.org" + assert "host" not in h2.headers + assert ":authority" in h2.headers + del h2.host_header + assert ":authority" not in h2.headers + + both_hdrs = treq(headers=( + (b":authority", b"example.com"), + (b"host", b"example.org"), + )) + both_hdrs.host_header = "foo.example.com" + assert both_hdrs.headers["Host"] == "foo.example.com" + assert both_hdrs.headers[":authority"] == "foo.example.com" + class TestRequestUtils: """ |
