diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-11-19 14:45:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-11-19 14:45:34 +0000 |
commit | a84c79f74f5743614fb50ba641b8bef84b43a9c8 (patch) | |
tree | e41afd6de5f571c5383f83b4a25bff515abba2ef | |
parent | 3babc536a5065b44e50a433df6cb8a19f4cd1be3 (diff) | |
download | rspamd-a84c79f74f5743614fb50ba641b8bef84b43a9c8.tar.gz rspamd-a84c79f74f5743614fb50ba641b8bef84b43a9c8.zip |
[Test] Fix dummy http server for keep-alive posts
-rwxr-xr-x | test/functional/util/dummy_http.py | 27 |
1 files 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, |