Skip to content

Commit

Permalink
Merge pull request #36 from pfeairheller/feat-fixes
Browse files Browse the repository at this point in the history
A few fixes for issues discovered when using large request bodies:
  • Loading branch information
SmithSamuelM authored Jul 8, 2024
2 parents 7aa6bea + 62b856c commit a37bdb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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

0 comments on commit a37bdb6

Please sign in to comment.