commit a84c79f: [Test] Fix dummy http server for keep-alive posts

Vsevolod Stakhov vsevolod at rspamd.com
Sat Nov 19 20:28:23 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-11-19 14:45:34 +0000
URL: https://github.com/rspamd/rspamd/commit/a84c79f74f5743614fb50ba641b8bef84b43a9c8

[Test] Fix dummy http server for keep-alive posts

---
 test/functional/util/dummy_http.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py
index c683d66a2..2ad4dcd40 100755
--- a/test/functional/util/dummy_http.py
+++ b/test/functional/util/dummy_http.py
@@ -16,10 +16,7 @@ PID = "/tmp/dummy_http.pid"
 
 
 class MyHandler(http.server.BaseHTTPRequestHandler):
-
-    def setup(self):
-        http.server.BaseHTTPRequestHandler.setup(self)
-        self.protocol_version = "HTTP/1.1" # allow connection: keep-alive
+    protocol_version = 'HTTP/1.1'
 
     def do_HEAD(self):
         if self.path == "/redirect1":
@@ -41,9 +38,8 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
         self.log_message("to be closed: " + repr(self.close_connection))
 
     def do_GET(self):
-        response = b"hello world"
-
         """Respond to a GET request."""
+        response = b"hello world"
         if self.path == "/empty":
             self.finish()
             return
@@ -72,8 +68,10 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
 
 
     def do_POST(self):
+        """Respond to a POST request."""
         response = b"hello post"
-        """Respond to a GET request."""
+        content_length = int(self.headers['Content-Length'])
+        body = self.rfile.read(content_length)
         if self.path == "/empty":
             self.finish()
             return
@@ -85,16 +83,21 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
             self.send_response(403)
         else:
             self.send_response(200)
-
-        if self.path == "/content-length":
-            self.send_header("Content-Length", str(len(response)))
-
         if self.path == "/map-simple":
-            response = "hello"
+            response = b"hello map"
+
+        self.send_header("Content-Length", str(len(response)))
+        conntype = self.headers.get('Connection', "").lower()
+        if conntype != 'keep-alive':
+            self.close_connection = True
+        else:
+            self.send_header("Connection", "keep-alive")
 
         self.send_header("Content-type", "text/plain")
         self.end_headers()
         self.wfile.write(response)
+        self.log_message("to be closed: %d, headers: %s, conn:'%s'" % (self.close_connection, str(self.headers), self.headers.get('Connection', "").lower()))
+        self.log_message("ka:'%s', pv:%s[%s]" % (str(conntype == 'keep-alive'), str(self.protocol_version >= "HTTP/1.1"), self.protocol_version))
 
 
 class ThreadingSimpleServer(socketserver.ThreadingMixIn,


More information about the Commits mailing list