MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / TestHTTPRequestHandler

Class TestHTTPRequestHandler

tests/python/test_xhr.py:8–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7def test_xhr():
8 class TestHTTPRequestHandler(BaseHTTPRequestHandler):
9 def log_request(self, *args) -> None:
10 return
11
12 def do_GET(self):
13 self.send_response(200)
14 self.end_headers()
15 self.wfile.write(b"get response")
16
17 def do_POST(self):
18 self.send_response(200)
19 self.send_header('Content-Type', 'application/json')
20 self.end_headers()
21 length = int(self.headers.get('Content-Length'))
22 json_string = self.rfile.read(length).decode("utf-8")
23 parameter_dict = json.loads(json_string)
24 parameter_dict["User-Agent"] = self.headers['User-Agent']
25 data = json.dumps(parameter_dict).encode("utf-8")
26 self.wfile.write(data)
27
28 httpd = HTTPServer(('localhost', 4001), TestHTTPRequestHandler)
29 thread = threading.Thread(target = httpd.serve_forever)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected