Skip to content

Instantly share code, notes, and snippets.

@ryochin
Created July 2, 2024 08:14
Show Gist options
  • Save ryochin/7e1fb48cd9a47e39c9f4b67676cd700c to your computer and use it in GitHub Desktop.
Save ryochin/7e1fb48cd9a47e39c9f4b67676cd700c to your computer and use it in GitHub Desktop.
Elixir: Tesla Middleware of adding content-length header field
defmodule Tesla.Middleware.ContentLength do
@behaviour Tesla.Middleware
@impl Tesla.Middleware
def call(env, next, _options) do
env
|> Tesla.put_header(
"content-length",
(env.body || "") |> String.length() |> Integer.to_string()
)
|> Tesla.run(next)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment