Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few fixes for issues discovered when using large request bodies: #36

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/hio/core/http/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def close(self):
"""
Close any resources
"""
if not self.closed and not self.ended:
if self.started and not self.closed and not self.ended:
self.write(b'') # in case chunked send empty chunk to terminate
self.ended = True
self.closed = True
Expand Down Expand Up @@ -355,7 +355,8 @@ def build(self):
if u'date' not in self.headers: # create Date header
self.headers[u'date'] = httping.httpDate1123(datetime.datetime.utcnow())

if self.chunkable and 'transfer-encoding' not in self.headers:
if self.chunkable and ('transfer-encoding' not in self.headers or
self.headers['transfer-encoding'] == 'chunked'):
self.chunked = True
self.headers[u'transfer-encoding'] = u'chunked'

Expand Down Expand Up @@ -606,7 +607,7 @@ def __init__(self,
defaultPort = 443
elif isinstance(servant, tcp.Server):
if scheme and scheme != u'http':
raise ValueError("Provided scheme '{0}' incompatible with servant".format(scheme))
raise ValueError("Provided scheme '{0}' incompatible with servant".format(scheme))
secured = False
scheme = 'http'
defaultPort = 80
Expand Down Expand Up @@ -797,12 +798,11 @@ def serviceReqs(self):
self.closeConnection(ca)
continue

logger.info("Parsed Request:\n%s %s {%s\n"
"%s\n%s\n", requestant.method,
requestant.path,
requestant.version,
requestant.headers,
requestant.body)
logger.info("Parsed Request: %s %s %s", requestant.method,
requestant.path,
requestant.version)
logger.debug("Headers/Body: %s -- %s", requestant.headers,
requestant.body)
# create or restart wsgi app responder here
environ = self.buildEnviron(requestant)
if ca not in self.reps:
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def respond(self):
fragment = pathSplits.fragment
data['fragment'] = fragment

data['headers'] = list(self.requestant.headers.items()) # copy.copy(self.requestant.headers) # make copy
data['headers'] = list(self.requestant.headers.items()) # copy.copy(self.requestant.headers) # make copy
data['body'] = self.requestant.body.decode('utf-8')
data['data'] = copy.copy(self.requestant.data) # make copy

Expand Down Expand Up @@ -1361,4 +1361,4 @@ def recur(self, tyme):

def exit(self):
""""""
self.server.close()
self.server.close()
2 changes: 1 addition & 1 deletion src/hio/core/tcp/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def serviceAxes(self):
wl=self.wl,
timeout=self.tymeout)
if ca in self.ixes and self.ixes[ca] is not remoter:
self.shutdownIx[ca]
self.shutdownIx(ca)
self.ixes[ca] = remoter


Expand Down
Loading