APIHttp.GZip

Http.GZip

Gzip content coding for HTTP bodies.

wrap compresses a handler’s responses for clients that accept gzip, and decodeRequests decompresses gzip request bodies before a handler sees them. Compression and decompression both stream.

acceptsGzip

acceptsGzip : List Header -> BoolSource

Whether the request’s Accept-Encoding headers accept gzip, honoring quality values and the * wildcard.

import Http exposing (Header(..))
import Http.GZip

Http.GZip.acceptsGzip [{ name = "Accept-Encoding", value = "br, gzip;q=0.5" }]
Http.GZip.acceptsGzip [{ name = "Accept-Encoding", value = "gzip;q=0, *" }] == False
Http.GZip.acceptsGzip [{ name = "Accept-Encoding", value = "*" }]
Http.GZip.acceptsGzip [] == False

decodeRequests

decodeRequests : Int -> (Request {Protocol, e} ->{Protocol, e} Response {Protocol, e}) -> Request {Protocol, e} ->{Protocol, e} Response {Protocol, e}Source

Decodes request bodies sent with Content-Encoding: gzip, up to limit decoded bytes, before handler sees them; the decoded request loses its Content-Encoding and Content-Length headers. identity passes through unchanged, and another content coding gets 415.

decoding

decoding : Int -> Reader {Protocol, e} -> Reader {Protocol, e}Source

A reader of the gzip-decoded content of input, reading concatenated gzip members as one stream. A corrupt or truncated stream raises Malformed, and more than limit decoded bytes BodyTooLarge.

encoding

encoding : Body e -> Body eSource

A body that sends body gzip-compressed. Its length is not known in advance, so it streams. An empty body stays empty.

wrap

wrap : (Request e ->{e} Response e) -> Request e ->{e} Response eSource

Runs handler and compresses its response when the request accepts gzip. HEAD requests, 204 and 304 responses, empty bodies, and responses that already have a Content-Encoding pass through unchanged. A compressed response streams chunked, even from a sized body, and gains Content-Encoding: gzip and Vary: Accept-Encoding.