appcues / mojito

An easy-to-use Elixir HTTP client, built on the low-level Mint library.
https://hexdocs.pm/mojito/Mojito.html
MIT License
349 stars 34 forks source link

Header non-string values #46

Closed egze closed 4 years ago

egze commented 4 years ago

I'm using mojito as a Http client for ExAws.

defmodule MyApp.S3.HttpClient do
  @behaviour ExAws.Request.HttpClient
  def request(method, url, body, headers, http_opts \\ []) do
    Mojito.request(method, url, headers, body, http_opts)
  end
end

When trying to download a file, I'm getting:

error] GenServer #PID<0.637.0> terminating
** (FunctionClauseError) no function clause matching in Mint.HTTP1.Request."-validate_header_value!/2-lc$^0/1-0-"/1

Last message (from #PID<0.478.0>): {:request, %Mojito.Request{body: "", headers: [{"x-amz-date", "20191213T171338Z"}, {"content-length", 0}], method: :head, opts: [], url: "https://s3.eu-central-1.amazonaws.com/bucket/file"}, #PID<0.478.0>, #Reference<0.938540534.2258632705.207122>}
State: %{conn: nil, hostname: nil, port: nil, protocol: nil, reply_tos: %{}, response_refs: %{}, responses: %{}}
Client #PID<0.478.0> is alive

This is happening because of this part {"content-length", 0}, if I preprocess the headers and convert the values to strings, then it works.

Should mojito be more permissive, and auto-convert the values? Will gladly do a PR.

gamache commented 4 years ago

Hi there! Sorry for the delayed reply. Your idea is a good one and I would happily accept a PR.

egze commented 4 years ago

@gamache Now that I think about it, maybe it's better to fix it in Mint? Somewhere here: https://github.com/elixir-mint/mint/blob/master/lib/mint/http1.ex#L237

What do you think?

egze commented 4 years ago

Let's see what Mint folks say. https://github.com/elixir-mint/mint/issues/235

egze commented 4 years ago

Ok, let's fix it in Mojito :)

gamache commented 4 years ago

Fixed in 0.6.2.