Skip to content
Permalink
Browse files

Correctly wait for a stream request to finish sending its data before…

… replying

Compare request content length and receive data length to decide if we can
route the request.
  • Loading branch information...
cvaroqui committed Jun 28, 2019
1 parent c22a7b6 commit a09f7e09fb876ab85b3d3fe4298e398600c97eba
Showing with 23 additions and 2 deletions.
  1. +23 −2 lib/osvcd_lsnr.py
@@ -714,9 +714,23 @@ def prepare_response(self, stream_id, status, data, content_type="application/js
self.streams[stream_id]["outbound"] += data
self.send_outbound(stream_id)

def can_end_stream(self, stream_id):
if "request" not in self.streams[stream_id]:
return True
if self.streams[stream_id].get("pushers"):
return False
datalen = self.streams[stream_id].get("datalen", 0)
headers = self.streams[stream_id].get("request_headers", {})
if not headers:
return True
expectedlen = int(headers.get("Content-Length", [0])[0])
if datalen >= expectedlen:
return True
return False

def send_outbound(self, stream_id):
data = self.streams[stream_id]["outbound"]
end_stream = not self.streams[stream_id].get("pushers") or "request" not in self.streams[stream_id]
end_stream = self.can_end_stream(stream_id)
window_size = self.h2conn.local_flow_control_window(stream_id)
window_size = min(window_size, len(data))
will_send = data[:window_size]
@@ -810,7 +824,10 @@ def h2_request_received(self, event):
data = b''
self.streams[stream_id] = {
"request": event,
"request_headers": HTTPHeaderMap(event.headers),
"data": data,
"datalen": 0,
"stream_ended": False,
"pushers": [],
"outbound": b'',
}
@@ -820,6 +837,8 @@ def h2_request_received(self, event):

def h2_data_received(self, event):
self.streams[event.stream_id]["data"] += event.data
self.streams[event.stream_id]["datalen"] += event.flow_controlled_length
self.streams[event.stream_id]["stream_ended"] = event.stream_ended
if not event.stream_ended:
return
status, content_type, data = self.h2_router(event.stream_id)
@@ -2413,8 +2432,10 @@ def action_events(self, nodename, stream_id=None, **kwargs):
self.rbac_requires(roles=["guest"], namespaces="ANY", **kwargs)
if not self.event_queue:
self.event_queue = queue.Queue()
if not self in self.parent.events_clients:
self.parent.events_clients.append(self)
self.events_stream_ids.append(stream_id)
if not stream_id in self.events_stream_ids:
self.events_stream_ids.append(stream_id)
if self.h2conn:
request_headers = HTTPHeaderMap(self.streams[stream_id]["request"].headers)
try:

0 comments on commit a09f7e0

Please sign in to comment.
You can’t perform that action at this time.