From 62b856c00ff4969b4eafcc41355d6332c4b562fe Mon Sep 17 00:00:00 2001 From: pfeairheller Date: Sun, 7 Jul 2024 16:02:40 -0700 Subject: [PATCH] A few fixes: - TCP Server fix call to "shutdownIx" to be a func call - HTTP Responder, allow for a clean exit after timeout - Handle chunk encoding if WSGI handler already sets "chunked" in transfer-encoding header - Remove body from default info level log of each request. For large bodies, this is too much. --- src/hio/core/http/serving.py | 22 +++++++++++----------- src/hio/core/tcp/serving.py | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/hio/core/http/serving.py b/src/hio/core/http/serving.py index f96e92c..647156f 100644 --- a/src/hio/core/http/serving.py +++ b/src/hio/core/http/serving.py @@ -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 @@ -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' @@ -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 @@ -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: @@ -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 @@ -1361,4 +1361,4 @@ def recur(self, tyme): def exit(self): """""" - self.server.close() + self.server.close() \ No newline at end of file diff --git a/src/hio/core/tcp/serving.py b/src/hio/core/tcp/serving.py index 0b367c3..d8ab445 100644 --- a/src/hio/core/tcp/serving.py +++ b/src/hio/core/tcp/serving.py @@ -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