Created
July 2, 2024 08:14
-
-
Save ryochin/7e1fb48cd9a47e39c9f4b67676cd700c to your computer and use it in GitHub Desktop.
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