Conduit v0.12.10 Conduit.Plug.Decode View Source

Decodes the message body based on the content encoding.

It uses in order of preference:

  1. The content encoding specified for the plug.
  2. The content encoding specified on the message.
  3. The default content encoding identity.

The location of the content encoding can be changed from content_encoding to a header with the :header option. This is useful for having multiple encodings, like a transfer encoding.

This plug should be used in an incoming pipeline. Generally before a Conduit.Plug.Parse plug.

Examples

plug Conduit.Plug.Decode
plug Conduit.Plug.Decode, content_encoding: "gzip"
plug Conduit.Plug.Decode, header: "transfer_encoding"

iex> import Conduit.Message
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_body("{}")
iex>   |> Conduit.Plug.Decode.run
iex> message.body
"{}"
iex> message.content_encoding
"identity"

iex> import Conduit.Message
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_body("{}")
iex>   |> Conduit.Plug.Decode.run(header: "transfer_encoding")
iex> message.body
"{}"
iex> get_header(message, "transfer_encoding")
"identity"

Link to this section Summary

Functions

Formats the message body based on the content encoding

Callback implementation for Conduit.Plug.init/1

Callback implementation for Conduit.Plug.run/2

Link to this section Functions

Link to this function call(message, next, opts) View Source

Formats the message body based on the content encoding.

Callback implementation for Conduit.Plug.init/1.

Link to this function run(message, opts \\ []) View Source

Callback implementation for Conduit.Plug.run/2.