Probably added gzip
This commit is contained in:
@@ -555,6 +555,7 @@ async def handle_xml_upload(
|
||||
):
|
||||
"""Endpoint for receiving XML files for conversion processing.
|
||||
Requires basic authentication and saves XML files to log directory.
|
||||
Supports gzip compression via Content-Encoding header.
|
||||
"""
|
||||
try:
|
||||
# Get the raw body content
|
||||
@@ -565,6 +566,20 @@ async def handle_xml_upload(
|
||||
status_code=400, detail="ERROR: No XML content provided"
|
||||
)
|
||||
|
||||
# Check if content is gzip compressed
|
||||
content_encoding = request.headers.get("content-encoding", "").lower()
|
||||
is_gzipped = content_encoding == "gzip"
|
||||
|
||||
# Decompress if gzipped
|
||||
if is_gzipped:
|
||||
try:
|
||||
body = gzip.decompress(body)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"ERROR: Failed to decompress gzip content: {e}",
|
||||
) from e
|
||||
|
||||
# Try to decode as UTF-8
|
||||
try:
|
||||
xml_content = body.decode("utf-8")
|
||||
@@ -594,21 +609,20 @@ async def handle_xml_upload(
|
||||
|
||||
_LOGGER.info("XML file saved to %s by user %s", log_filename, username)
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "XML file received and saved",
|
||||
"filename": log_filename.name,
|
||||
"size_bytes": len(body),
|
||||
"authenticated_user": username,
|
||||
response_headers = {
|
||||
"Content-Type": "application/xml; charset=utf-8",
|
||||
"X-AlpineBits-Server-Accept-Encoding": "gzip",
|
||||
}
|
||||
|
||||
return Response(
|
||||
content="Xml received", headers=response_headers, status_code=200
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
_LOGGER.exception("Error in handle_xml_upload")
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Error processing XML upload"
|
||||
) from e
|
||||
raise HTTPException(status_code=500, detail="Error processing XML upload")
|
||||
|
||||
|
||||
# UNUSED
|
||||
|
||||
Reference in New Issue
Block a user