Skip to content

Commit

Permalink
[Test] Another try to fix a dummy server
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Dec 5, 2022
1 parent 22604a2 commit dddd4a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions test/functional/lua/tcp.lua
Expand Up @@ -55,7 +55,7 @@ local function http_simple_tcp_ssl_symbol(task)
read = true,
ssl = true,
ssl_noverify = true,
port = 14433,
port = 18081,
})
end
Expand Down Expand Up @@ -96,7 +96,7 @@ local function http_large_tcp_ssl_symbol(task)
ssl = true,
stop_pattern = '\n',
ssl_noverify = true,
port = 14433,
port = 18081,
timeout = 20,
})
else
Expand Down
40 changes: 28 additions & 12 deletions test/functional/util/dummy_https.py
Expand Up @@ -10,6 +10,7 @@
import time

import dummy_killer
from urllib.parse import urlparse, parse_qs

PORT = 18081
HOST_NAME = '127.0.0.1'
Expand Down Expand Up @@ -62,14 +63,13 @@ def do_GET(self):

def do_POST(self):
"""Respond to a POST request."""

content_length = int(self.headers['Content-Length'])
response = b'hello post'

response = b"hello post"
content_length = int(self.headers.get('Content-Length', "0")) or 0
content_type = "text/plain"
url = urlparse(self.path)
self.path = url.path
if content_length > 0:
body = self.rfile.read(content_length)
response = b"hello post: " + bytes(len(body))

_ = self.rfile.read(content_length)
if self.path == "/empty":
self.finish()
return
Expand All @@ -81,14 +81,30 @@ def do_POST(self):
self.send_response(403)
else:
self.send_response(200)
if self.path == "/map-simple":
response = b"hello map"
if self.path == "/map-query":
query = parse_qs(url.query)
if query['key'] == 'au':
response = b"hit"
else:
self.send_response(404)
if self.path == "/settings":
response = b"{\"actions\": { \"reject\": 1.0}, \"symbols\": { \"EXTERNAL_SETTINGS\": 1.0 }}"
content_type = "application/json"

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")

if self.path == "/content-length":
self.send_header("Content-Length", str(len(response)))

self.send_header("Content-type", "text/plain")
self.send_header("Content-type", content_type)
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,
http.server.HTTPServer):
Expand Down

0 comments on commit dddd4a5

Please sign in to comment.