Module rhymuweb::coding[][src]

This module contains helper functions for encoding and decoding the bodies of HTTP requests and responses. There are two kinds of coding: text coding and content coding. Content coding changes the bytes of the body in order to represent it differently; for example, to compress the body to a smaller size. Text coding is how the bytes of the body are interpreted as text, and therefore how it can be converted to/from a Rust string.

Functions

decode_body

Attempt to reverse any content coding that has been performed on the given message body, as indicated in the given message headers. The content codings that were performed on the body are listed in the Content-Encoding header, in the same order that the encoding was performed. Therefore, to decode the body, the decoding is performed in reverse order. Decoding is stopped if any unrecognized coding is encountered, or any error occurs during the decoding process. Any codings successfully decoded are removed from the Content-Encoding header, and the header itself is removed if all codings are decoded.

decode_body_as_text

Attempt to decode the given message body as text. This will only work if the given headers for the message contain a Content-Type header where the type is text, the charset parameter (iso-8859-1 is assumed if charset is missing) is a text encoding recognized and supported by the encoding_rs crate, and the text is successfully decoded.