Conduit v0.12.10 Conduit.Plug.Encode View Source

Encodes 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 outgoing pipeline. Generally after a Conduit.Plug.Format plug.

Examples

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

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

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

Link to this section Summary

Functions

Encodes 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

Encodes 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.