moonzero · control plane v0.15.0 · 49 packages · 4 targets · Apache-2.0 docs / edge / gunzip GitHub

08 / EDGE

gunzip

Read a Content-Encoding: gzip body, inflate it, and hand the application the plain bytes, with an optional cap on the inflated size so a compression bomb stops at the limit rather than in memory.

fn is_gzip_encoding(value : String) -> Bool

fnWhether a Content-Encoding value asks for gzip. The header is a comma separated list and gzip may be one of several codings, so the match is on the token, not the whole value.

fn gunzip(limit~ : Int32 = 0) -> Middleware

fnGunzip middleware: when the request declares Content-Encoding: gzip, buffer the body, inflate it, and hand the wrapped application one HttpRequest carrying the plain body. A body that will not inflate is answered 400 Bad Request without reaching the application. The application is handed a scope without Content-Encoding and without the compressed body's Content-Length: both describe bytes that no longer exist by the time it looks, and a handler that trusted either would misread the request. limit caps the *decompressed* size in bytes, the number a compression bomb inflates to; 0 removes the cap, which is what a service that has already bounded the compressed body at the edge wants. Anything but an HTTP scope, a request without the header, or one with no body at all passes through untouched.