From 228c76dbd2ca5331ecaa2ceaaf335b28def56a80 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sun, 23 Oct 2022 19:16:38 +0100 Subject: [PATCH] Fix bug where internal rpc requests repeated the full URL Internal POST requests were using a "proxy" HTTP syntax for their requests, which is incorrect. --- ai_web_common/rpc/core.py | 11 ++++------- ai_web_common/rpc/test/__init__.py | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ai_web_common/rpc/core.py b/ai_web_common/rpc/core.py index ba1bb36..7cc53ab 100644 --- a/ai_web_common/rpc/core.py +++ b/ai_web_common/rpc/core.py @@ -139,7 +139,8 @@ def _json_request_encoder(req): def _json_response_decoder(resp): - if not resp.getheader('Content-Type').startswith('application/json'): + content_type = resp.getheader('Content-Type') + if not content_type or not content_type.startswith('application/json'): raise ValueError('response is not application/json') reader = codecs.getreader('utf-8') @@ -264,12 +265,8 @@ class ClientStub(): pass actual_url = urllib3.util.Url( - parsed_url.scheme, - parsed_url.auth, - target_addr, - target_port, - parsed_url.path, - parsed_url.query, + path=parsed_url.path, + query=parsed_url.query, ) resp = pool.urlopen( 'POST', diff --git a/ai_web_common/rpc/test/__init__.py b/ai_web_common/rpc/test/__init__.py index 91ea221..621c1d8 100644 --- a/ai_web_common/rpc/test/__init__.py +++ b/ai_web_common/rpc/test/__init__.py @@ -101,6 +101,10 @@ class HTTPWorker(threading.Thread): class _Handler(http.server.BaseHTTPRequestHandler): def do_POST(self): + if not self.path.startswith('/'): + self.send_response(400) + self.end_headers() + return counters.inc(key) with request_counter_lock: rc = request_counter['value'] -- GitLab