Gateway: Factor out the guts of bottle /upload/ route for easier testing

This commit is contained in:
Athanasius 2022-08-29 15:30:27 +01:00
parent 5c0515e9c6
commit bc5f7e9059
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62

View File

@ -308,13 +308,25 @@ def parse_and_error_handle(data: bytes) -> str:
@app.route("/upload/", method=["OPTIONS", "POST"])
def upload() -> str:
"""
Handle an /upload/ request.
Process an /upload/ request.
:return: The processed message, else error string.
"""
return handle_upload(request.headers, request.body.read(), response)
def handle_upload(headers, body, response) -> str:
"""
Handle an upload request.
This is separate from, and called by, the bottle route to more easily
enable functional/unit testing.
:return: The processed message, else error string.
"""
try:
# Body may or may not be compressed.
message_body = get_decompressed_message(request.headers, request.body.read())
message_body = get_decompressed_message(headers, body)
except zlib.error as exc:
# Some languages and libs do a crap job zlib compressing stuff. Provide