Skip to content

Commit

Permalink
fix request body handling - fixes benoitc#3301
Browse files Browse the repository at this point in the history
  • Loading branch information
oallenj committed Sep 30, 2024
1 parent 903792f commit 8160505
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions gunicorn/http/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ def __init__(self, cfg, source, source_addr):
def __iter__(self):
return self

def __next__(self):
# Stop if HTTP dictates a stop.
if self.mesg and self.mesg.should_close():
raise StopIteration()

def finish_body(self):
# Discard any unread body of the previous message
if self.mesg:
data = self.mesg.body.read(8192)
while data:
data = self.mesg.body.read(8192)

def __next__(self):
# Stop if HTTP dictates a stop.
if self.mesg and self.mesg.should_close():
raise StopIteration()
self.finish_body()

# Parse the next request
self.req_count += 1
self.mesg = self.mesg_class(self.cfg, self.unreader, self.source_addr, self.req_count)
Expand Down
1 change: 1 addition & 0 deletions gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def handle(self, conn):
# handle the request
keepalive = self.handle_request(req, conn)
if keepalive:
conn.parser.finish_body()
return (keepalive, conn)
except http.errors.NoMoreData as e:
self.log.debug("Ignored premature client disconnection. %s", e)
Expand Down

0 comments on commit 8160505

Please sign in to comment.