|
22 | 22 | from __future__ import annotations |
23 | 23 |
|
24 | 24 | import base64 |
25 | | -import binascii |
26 | 25 | import json |
27 | 26 | import logging |
28 | 27 | import warnings |
29 | 28 | from collections.abc import Callable |
30 | 29 | from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer |
31 | 30 | from threading import Thread |
32 | 31 | from typing import TYPE_CHECKING, Any, Generic, Self, TypeVar |
33 | | -from urllib.parse import parse_qs, urlparse |
| 32 | +from urllib.parse import urlparse |
34 | 33 |
|
35 | 34 | from pact import __version__ |
36 | 35 | from pact.v3._util import find_free_port |
@@ -238,39 +237,6 @@ def version_string(self) -> str: |
238 | 237 | """ |
239 | 238 | return f"Pact Python Message Relay/{__version__}" |
240 | 239 |
|
241 | | - def _process(self) -> tuple[bytes | None, dict[str, str] | None]: |
242 | | - """ |
243 | | - Process the request. |
244 | | -
|
245 | | - Read the body and headers from the request and perform some common logic |
246 | | - shared between GET and POST requests. |
247 | | -
|
248 | | - Returns: |
249 | | - body: |
250 | | - The body of the request as a byte string, if present. |
251 | | -
|
252 | | - metadata: |
253 | | - The metadata of the request, if present. |
254 | | - """ |
255 | | - if content_length := self.headers.get("Content-Length"): |
256 | | - body = self.rfile.read(int(content_length)) |
257 | | - else: |
258 | | - body = None |
259 | | - |
260 | | - if data := self.headers.get("Pact-Message-Metadata"): |
261 | | - try: |
262 | | - metadata = json.loads(base64.b64decode(data)) |
263 | | - except binascii.Error as err: |
264 | | - msg = "Unable to base64 decode Pact metadata header." |
265 | | - raise RuntimeError(msg) from err |
266 | | - except json.JSONDecodeError as err: |
267 | | - msg = "Unable to JSON decode Pact metadata header." |
268 | | - raise RuntimeError(msg) from err |
269 | | - else: |
270 | | - return body, metadata |
271 | | - |
272 | | - return body, None |
273 | | - |
274 | 240 | def do_POST(self) -> None: # noqa: N802 |
275 | 241 | """ |
276 | 242 | Handle a POST request. |
@@ -476,19 +442,11 @@ def do_POST(self) -> None: # noqa: N802 |
476 | 442 | self.send_error(404, "Not Found") |
477 | 443 | return |
478 | 444 |
|
479 | | - if query := url.query: |
480 | | - data: dict[str, Any] = parse_qs(query) |
481 | | - # Convert single-element lists to single values |
482 | | - for k, v in data.items(): |
483 | | - if isinstance(v, list) and len(v) == 1: |
484 | | - data[k] = v[0] |
485 | | - |
486 | | - else: |
487 | | - content_length = self.headers.get("Content-Length") |
488 | | - if not content_length: |
489 | | - self.send_error(400, "Bad Request") |
490 | | - return |
491 | | - data = json.loads(self.rfile.read(int(content_length))) |
| 445 | + content_length = self.headers.get("Content-Length") |
| 446 | + if not content_length: |
| 447 | + self.send_error(400, "Bad Request") |
| 448 | + return |
| 449 | + data = json.loads(self.rfile.read(int(content_length))) |
492 | 450 |
|
493 | 451 | state = data.pop("state") |
494 | 452 | action = data.pop("action") |
|
0 commit comments