mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-03-28 01:44:17 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e99691e2c | ||
|
|
c3fa3acd95 | ||
|
|
c6c3b8f447 | ||
|
|
ac871b5874 |
@@ -599,9 +599,6 @@ class Http2SingleStreamLayer(httpbase._HttpTransmissionLayer, basethread.BaseThr
|
|||||||
def send_response_headers(self, response):
|
def send_response_headers(self, response):
|
||||||
headers = response.headers.copy()
|
headers = response.headers.copy()
|
||||||
headers.insert(0, ":status", str(response.status_code))
|
headers.insert(0, ":status", str(response.status_code))
|
||||||
for forbidden_header in h2.utilities.CONNECTION_HEADERS:
|
|
||||||
if forbidden_header in headers:
|
|
||||||
del headers[forbidden_header]
|
|
||||||
with self.connections[self.client_conn].lock:
|
with self.connections[self.client_conn].lock:
|
||||||
self.connections[self.client_conn].safe_send_headers(
|
self.connections[self.client_conn].safe_send_headers(
|
||||||
self.raise_zombie,
|
self.raise_zombie,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
IVERSION = (2, 0, 0)
|
IVERSION = (2, 0, 1)
|
||||||
VERSION = ".".join(str(i) for i in IVERSION)
|
VERSION = ".".join(str(i) for i in IVERSION)
|
||||||
PATHOD = "pathod " + VERSION
|
PATHOD = "pathod " + VERSION
|
||||||
MITMPROXY = "mitmproxy " + VERSION
|
MITMPROXY = "mitmproxy " + VERSION
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -64,7 +64,7 @@ setup(
|
|||||||
"click>=6.2, <7",
|
"click>=6.2, <7",
|
||||||
"certifi>=2015.11.20.1", # no semver here - this should always be on the last release!
|
"certifi>=2015.11.20.1", # no semver here - this should always be on the last release!
|
||||||
"construct>=2.8, <2.9",
|
"construct>=2.8, <2.9",
|
||||||
"cryptography>=1.3, <1.8",
|
"cryptography>=1.3, <1.9",
|
||||||
"cssutils>=1.0.1, <1.1",
|
"cssutils>=1.0.1, <1.1",
|
||||||
"h2>=2.5.1, <3",
|
"h2>=2.5.1, <3",
|
||||||
"html2text>=2016.1.8, <=2016.9.19",
|
"html2text>=2016.1.8, <=2016.9.19",
|
||||||
@@ -74,7 +74,7 @@ setup(
|
|||||||
"passlib>=1.6.5, <1.8",
|
"passlib>=1.6.5, <1.8",
|
||||||
"pyasn1>=0.1.9, <0.3",
|
"pyasn1>=0.1.9, <0.3",
|
||||||
"pyOpenSSL>=16.0, <17.0",
|
"pyOpenSSL>=16.0, <17.0",
|
||||||
"pyparsing>=2.1.3, <2.2",
|
"pyparsing>=2.1.3, <2.3",
|
||||||
"pyperclip>=1.5.22, <1.6",
|
"pyperclip>=1.5.22, <1.6",
|
||||||
"requests>=2.9.1, <3",
|
"requests>=2.9.1, <3",
|
||||||
"ruamel.yaml>=0.13.2, <0.14",
|
"ruamel.yaml>=0.13.2, <0.14",
|
||||||
|
|||||||
@@ -271,75 +271,6 @@ class TestSimple(_Http2Test):
|
|||||||
assert response_body_buffer == b'response body'
|
assert response_body_buffer == b'response body'
|
||||||
|
|
||||||
|
|
||||||
@requires_alpn
|
|
||||||
class TestForbiddenHeaders(_Http2Test):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def handle_server_event(cls, event, h2_conn, rfile, wfile):
|
|
||||||
if isinstance(event, h2.events.ConnectionTerminated):
|
|
||||||
return False
|
|
||||||
elif isinstance(event, h2.events.StreamEnded):
|
|
||||||
import warnings
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
# Ignore UnicodeWarning:
|
|
||||||
# h2/utilities.py:64: UnicodeWarning: Unicode equal comparison
|
|
||||||
# failed to convert both arguments to Unicode - interpreting
|
|
||||||
# them as being unequal.
|
|
||||||
# elif header[0] in (b'cookie', u'cookie') and len(header[1]) < 20:
|
|
||||||
|
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
|
|
||||||
h2_conn.config.validate_outbound_headers = False
|
|
||||||
h2_conn.send_headers(event.stream_id, [
|
|
||||||
(':status', '200'),
|
|
||||||
('keep-alive', 'foobar'),
|
|
||||||
])
|
|
||||||
h2_conn.send_data(event.stream_id, b'response body')
|
|
||||||
h2_conn.end_stream(event.stream_id)
|
|
||||||
wfile.write(h2_conn.data_to_send())
|
|
||||||
wfile.flush()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def test_forbidden_headers(self):
|
|
||||||
client, h2_conn = self._setup_connection()
|
|
||||||
|
|
||||||
self._send_request(
|
|
||||||
client.wfile,
|
|
||||||
h2_conn,
|
|
||||||
headers=[
|
|
||||||
(':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
|
|
||||||
(':method', 'GET'),
|
|
||||||
(':scheme', 'https'),
|
|
||||||
(':path', '/'),
|
|
||||||
])
|
|
||||||
|
|
||||||
done = False
|
|
||||||
while not done:
|
|
||||||
try:
|
|
||||||
raw = b''.join(http2.read_raw_frame(client.rfile))
|
|
||||||
events = h2_conn.receive_data(raw)
|
|
||||||
except exceptions.HttpException:
|
|
||||||
print(traceback.format_exc())
|
|
||||||
assert False
|
|
||||||
|
|
||||||
client.wfile.write(h2_conn.data_to_send())
|
|
||||||
client.wfile.flush()
|
|
||||||
|
|
||||||
for event in events:
|
|
||||||
if isinstance(event, h2.events.ResponseReceived):
|
|
||||||
assert 'keep-alive' not in event.headers
|
|
||||||
elif isinstance(event, h2.events.StreamEnded):
|
|
||||||
done = True
|
|
||||||
|
|
||||||
h2_conn.close_connection()
|
|
||||||
client.wfile.write(h2_conn.data_to_send())
|
|
||||||
client.wfile.flush()
|
|
||||||
|
|
||||||
assert len(self.master.state.flows) == 1
|
|
||||||
assert self.master.state.flows[0].response.status_code == 200
|
|
||||||
assert self.master.state.flows[0].response.headers['keep-alive'] == 'foobar'
|
|
||||||
|
|
||||||
|
|
||||||
@requires_alpn
|
@requires_alpn
|
||||||
class TestRequestWithPriority(_Http2Test):
|
class TestRequestWithPriority(_Http2Test):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user