INNER CODE UNIT · Python

_decompress_request_body

ministackorg/ministack · ministack/app.py:603

def _decompress_request_body(body: bytes, headers: dict) -> bytes:
    """Inflate a gzip-compressed request body and drop the gzip token.

    Smithy's ``@requestCompression`` trait makes AWS SDKs gzip a request body
    once it passes ``REQUEST_MIN_COMPRESSION_SIZE_BYTES`` (default 10240) and
    send ``Content-Encoding: gzip``. CloudWatch ``PutMetricData`` carries the
    trait today; any client may compress a body it is allowed to compress.
    Returns ``body`` unchanged when the header does not ask for gzip.
    """
    content_encoding = headers.get("content-encoding", "")
    if "gzip" not in content_encoding.lower():
        return body
    try:
        inflated = gzip.decompress(body)
    except (OSError, EOFError) as e:
        # A body flagged gzip that will not inflate is a real bug. Log it and
        # pass the raw bytes on, so the handler's own error surfaces.
        logger.warning("gzip request body failed to inflate: %s", e)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…