The main use case for this library is to compress the response body of a given list of endpoints. To do this, you can simply add Dream_encoding.compress to your list of middlewares:
For more advanced use cases, some utility functions are also exposed. In particular, functions to retrieve the Content-Encoding and Accept-Encoding headers (respectively, content_encoding and accept_encoding), as well as with_encoded_body, a function to compress the body of a response.
As of now, the supported encoding directives are deflate and gzip. More directive will be supported when their support land in decompress, the underlying compression library used by Dream_encoding.
Middleware that reads the Content-Encoding of the request and decompresses the body if all of the directives of the header are supported.
If one or more of the directive is not supported, an HTTP response 415 Unsupported Media Type is returned to the client.
Note that although HTTP supports encoding requests, it is rarely used in practice. See compress to for a middleware that compresses the responses instead.
with_encoded_body ?algorithm body response replaces the body of the response with body compressed with algorithm and adds the corresponding Content-Encoding header.
algorithm defaults to `Deflate.
Sourceval accepted_encodings :
'aDream.message->[ `Gzip | `Compress| `Deflate| `Identity| `Any| `Unknown of string ] list
option
Retrieve the list of accepted encoding directives from the Accept-Encoding header, ordered by quality weight in decreasing order.
If the request does not have an Accept-Encoding header, this returns None.
Sourceval accepted_encodings_with_weights :
'aDream.message->([ `Gzip | `Compress| `Deflate| `Identity| `Any| `Unknown of string ]
* int)
list
option
Same as accepted_encoding, but returns the quality weights associated to the encoding directive.
Sourceval content_encodings :
'aDream.message->[ `Gzip | `Compress| `Deflate| `Identity| `Any| `Unknown of string ] list
option
Retrieve the list of content encoding directives from the Content-Encoding header.
If the request does not have an Content-Encoding header, this returns None.