Added urllib parsing for gzip compressed content
This commit is contained in:
@@ -21,6 +21,8 @@ import os
|
||||
import gzip
|
||||
import xml.etree.ElementTree as ET
|
||||
from .alpinebits_server import AlpineBitsServer, Version
|
||||
import urllib.parse
|
||||
|
||||
|
||||
# HTTP Basic auth for AlpineBits
|
||||
security_basic = HTTPBasic()
|
||||
@@ -441,12 +443,17 @@ async def alpinebits_server_handshake(
|
||||
# Get content type before processing
|
||||
content_type = request.headers.get("Content-Type", "")
|
||||
|
||||
logger.info(f"Content-Type: {content_type}")
|
||||
logger.info(f"Content-Encoding: {content_encoding}")
|
||||
|
||||
# Get request body
|
||||
body = await request.body()
|
||||
|
||||
# Decompress if needed
|
||||
if is_compressed:
|
||||
try:
|
||||
logger.info(f"Raw compressed body (first 200 bytes): {body[:200]!r}")
|
||||
|
||||
body = gzip.decompress(body)
|
||||
logger.info("Successfully decompressed gzip content")
|
||||
|
||||
@@ -454,7 +461,7 @@ async def alpinebits_server_handshake(
|
||||
logs_dir = "logs"
|
||||
if not os.path.exists(logs_dir):
|
||||
os.makedirs(logs_dir, mode=0o755, exist_ok=True)
|
||||
log_filename = f"{logs_dir}/alpinebits_request_{datetime.now().strftime('%Y%m%d_%H%M%S')}.xml"
|
||||
log_filename = f"{logs_dir}/alpinebits_request_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
||||
with open(log_filename, "wb") as f:
|
||||
f.write(body)
|
||||
|
||||
@@ -466,13 +473,23 @@ async def alpinebits_server_handshake(
|
||||
)
|
||||
|
||||
# Check content type (after decompression)
|
||||
if "multipart/form-data" not in content_type:
|
||||
if "multipart/form-data" not in content_type and "application/x-www-form-urlencoded" not in content_type:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="ERROR: Content-Type must be multipart/form-data"
|
||||
)
|
||||
|
||||
logger.info(f"Request body length: {len(body)} bytes")
|
||||
# log body to file for debugging
|
||||
logs_dir = "logs"
|
||||
if not os.path.exists(logs_dir):
|
||||
os.makedirs(logs_dir, mode=0o755, exist_ok=True)
|
||||
log_filename = f"{logs_dir}/alpinebits_request_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
||||
with open(log_filename, "wb") as f:
|
||||
f.write(body)
|
||||
|
||||
# Parse multipart data
|
||||
if "multipart/form-data" in content_type:
|
||||
try:
|
||||
form_data = parse_multipart_data(content_type, body)
|
||||
except Exception as e:
|
||||
@@ -480,6 +497,14 @@ async def alpinebits_server_handshake(
|
||||
status_code=400,
|
||||
detail=f"ERROR: Failed to parse multipart/form-data: {str(e)}"
|
||||
)
|
||||
elif "application/x-www-form-urlencoded" in content_type:
|
||||
# Parse as urlencoded
|
||||
form_data = dict(urllib.parse.parse_qsl(body.decode("utf-8")))
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="ERROR: Content-Type must be multipart/form-data or application/x-www-form-urlencoded"
|
||||
)
|
||||
|
||||
# Check for required action parameter
|
||||
action = form_data.get("action")
|
||||
|
||||
Reference in New Issue
Block a user