mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
commit
595a01de4e
@ -26,11 +26,6 @@ class SafeH2Connection(H2Connection):
|
|||||||
self.conn = conn
|
self.conn = conn
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
|
|
||||||
def safe_close_connection(self, error_code):
|
|
||||||
with self.lock:
|
|
||||||
self.close_connection(error_code)
|
|
||||||
self.conn.send(self.data_to_send())
|
|
||||||
|
|
||||||
def safe_increment_flow_control(self, stream_id, length):
|
def safe_increment_flow_control(self, stream_id, length):
|
||||||
if length == 0:
|
if length == 0:
|
||||||
return
|
return
|
||||||
@ -47,7 +42,7 @@ class SafeH2Connection(H2Connection):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
try:
|
try:
|
||||||
self.reset_stream(stream_id, error_code)
|
self.reset_stream(stream_id, error_code)
|
||||||
except h2.exceptions.StreamClosedError:
|
except h2.exceptions.StreamClosedError: # pragma: no cover
|
||||||
# stream is already closed - good
|
# stream is already closed - good
|
||||||
pass
|
pass
|
||||||
self.conn.send(self.data_to_send())
|
self.conn.send(self.data_to_send())
|
||||||
@ -59,7 +54,7 @@ class SafeH2Connection(H2Connection):
|
|||||||
|
|
||||||
def safe_send_headers(self, is_zombie, stream_id, headers):
|
def safe_send_headers(self, is_zombie, stream_id, headers):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if is_zombie():
|
if is_zombie(): # pragma: no cover
|
||||||
return
|
return
|
||||||
self.send_headers(stream_id, headers)
|
self.send_headers(stream_id, headers)
|
||||||
self.conn.send(self.data_to_send())
|
self.conn.send(self.data_to_send())
|
||||||
@ -69,7 +64,7 @@ class SafeH2Connection(H2Connection):
|
|||||||
position = 0
|
position = 0
|
||||||
while position < len(chunk):
|
while position < len(chunk):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if is_zombie():
|
if is_zombie(): # pragma: no cover
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
return
|
return
|
||||||
max_outbound_frame_size = self.max_outbound_frame_size
|
max_outbound_frame_size = self.max_outbound_frame_size
|
||||||
@ -83,7 +78,7 @@ class SafeH2Connection(H2Connection):
|
|||||||
self.lock.release()
|
self.lock.release()
|
||||||
position += max_outbound_frame_size
|
position += max_outbound_frame_size
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if is_zombie():
|
if is_zombie(): # pragma: no cover
|
||||||
return
|
return
|
||||||
self.end_stream(stream_id)
|
self.end_stream(stream_id)
|
||||||
self.conn.send(self.data_to_send())
|
self.conn.send(self.data_to_send())
|
||||||
@ -95,8 +90,6 @@ class Http2Layer(Layer):
|
|||||||
super(Http2Layer, self).__init__(ctx)
|
super(Http2Layer, self).__init__(ctx)
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.streams = dict()
|
self.streams = dict()
|
||||||
self.client_reset_streams = []
|
|
||||||
self.server_reset_streams = []
|
|
||||||
self.server_to_client_stream_ids = dict([(0, 0)])
|
self.server_to_client_stream_ids = dict([(0, 0)])
|
||||||
self.client_conn.h2 = SafeH2Connection(self.client_conn, client_side=False)
|
self.client_conn.h2 = SafeH2Connection(self.client_conn, client_side=False)
|
||||||
|
|
||||||
@ -112,9 +105,6 @@ class Http2Layer(Layer):
|
|||||||
|
|
||||||
def connect(self): # pragma: no cover
|
def connect(self): # pragma: no cover
|
||||||
raise ValueError("CONNECT inside an HTTP2 stream is not supported.")
|
raise ValueError("CONNECT inside an HTTP2 stream is not supported.")
|
||||||
# self.ctx.connect()
|
|
||||||
# self.server_conn.connect()
|
|
||||||
# self._initiate_server_conn()
|
|
||||||
|
|
||||||
def set_server(self): # pragma: no cover
|
def set_server(self): # pragma: no cover
|
||||||
raise NotImplementedError("Cannot change server for HTTP2 connections.")
|
raise NotImplementedError("Cannot change server for HTTP2 connections.")
|
||||||
@ -162,9 +152,6 @@ class Http2Layer(Layer):
|
|||||||
self.streams[eid].data_finished.set()
|
self.streams[eid].data_finished.set()
|
||||||
elif isinstance(event, h2.events.StreamReset):
|
elif isinstance(event, h2.events.StreamReset):
|
||||||
self.streams[eid].zombie = time.time()
|
self.streams[eid].zombie = time.time()
|
||||||
self.client_reset_streams.append(self.streams[eid].client_stream_id)
|
|
||||||
if self.streams[eid].server_stream_id:
|
|
||||||
self.server_reset_streams.append(self.streams[eid].server_stream_id)
|
|
||||||
if eid in self.streams and event.error_code == 0x8:
|
if eid in self.streams and event.error_code == 0x8:
|
||||||
if is_server:
|
if is_server:
|
||||||
other_stream_id = self.streams[eid].client_stream_id
|
other_stream_id = self.streams[eid].client_stream_id
|
||||||
@ -227,6 +214,7 @@ class Http2Layer(Layer):
|
|||||||
try:
|
try:
|
||||||
raw_frame = b''.join(http2_read_raw_frame(source_conn.rfile))
|
raw_frame = b''.join(http2_read_raw_frame(source_conn.rfile))
|
||||||
except:
|
except:
|
||||||
|
# read frame failed: connection closed
|
||||||
for stream in self.streams.values():
|
for stream in self.streams.values():
|
||||||
stream.zombie = time.time()
|
stream.zombie = time.time()
|
||||||
return
|
return
|
||||||
@ -346,7 +334,7 @@ class Http2SingleStreamLayer(_HttpTransmissionLayer, threading.Thread):
|
|||||||
|
|
||||||
with self.server_conn.h2.lock:
|
with self.server_conn.h2.lock:
|
||||||
# We must not assign a stream id if we are already a zombie.
|
# We must not assign a stream id if we are already a zombie.
|
||||||
if self.zombie:
|
if self.zombie: # pragma: no cover
|
||||||
return
|
return
|
||||||
|
|
||||||
self.server_stream_id = self.server_conn.h2.get_next_available_stream_id()
|
self.server_stream_id = self.server_conn.h2.get_next_available_stream_id()
|
||||||
@ -388,7 +376,7 @@ class Http2SingleStreamLayer(_HttpTransmissionLayer, threading.Thread):
|
|||||||
while self.response_data_queue.qsize() > 0:
|
while self.response_data_queue.qsize() > 0:
|
||||||
yield self.response_data_queue.get()
|
yield self.response_data_queue.get()
|
||||||
return
|
return
|
||||||
if self.zombie:
|
if self.zombie: # pragma: no cover
|
||||||
return
|
return
|
||||||
|
|
||||||
def send_response_headers(self, response):
|
def send_response_headers(self, response):
|
||||||
@ -410,9 +398,6 @@ class Http2SingleStreamLayer(_HttpTransmissionLayer, threading.Thread):
|
|||||||
# RFC 7540 8.1: An HTTP request/response exchange fully consumes a single stream.
|
# RFC 7540 8.1: An HTTP request/response exchange fully consumes a single stream.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def connect(self): # pragma: no cover
|
|
||||||
raise ValueError("CONNECT inside an HTTP2 stream is not supported.")
|
|
||||||
|
|
||||||
def set_server(self, *args, **kwargs): # pragma: no cover
|
def set_server(self, *args, **kwargs): # pragma: no cover
|
||||||
# do not mess with the server connection - all streams share it.
|
# do not mess with the server connection - all streams share it.
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user