Created
July 2, 2024 08:14
Elixir: Tesla Middleware of adding content-length header field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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