Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request headers should allow string keys #104

Closed
smoynes opened this issue Feb 11, 2017 · 1 comment
Closed

Request headers should allow string keys #104

smoynes opened this issue Feb 11, 2017 · 1 comment

Comments

@smoynes
Copy link

smoynes commented Feb 11, 2017

Similar #99, request headers may come from user input. For example, a proxy application may need to pass all headers from an incoming request along to an upstream server. It would be nice if the headers argument could also take the header name as a string both to preserve case and also to avoid converting user input to atoms.

With Elixir >= 1.4, an argument error is raised when passing a list of tuples with string keys:

Interactive Elixir (1.4.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HTTPotion.get "http://httpbin.org/get", headers: [{"foo", "bar"}]
** (ArgumentError) expected a keyword list as the second argument, got: [{"foo", "bar"}]
       (elixir) lib/keyword.ex:589: Keyword.merge/2
    (httpotion) lib/httpotion.ex:355: HTTPotion.process_arguments/3
    (httpotion) lib/httpotion.ex:355: HTTPotion.request/3

However, this usage succeeds with Elixir < 1.4

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HTTPotion.get "http://httpbin.org/get", headers: [{"foo", "bar"}]
%HTTPotion.Response{body: "{\n  \"args\": {}, \n  \"headers\": {\n    \"Content-Length\": \"0\", \n    \"Foo\": \"bar\", \n    \"Host\": \"httpbin.org\"\n  }, \n  \"origin\": \"172.10.1.39\", \n  \"url\": \"http://httpbin.org/get\"\n}\n",
 headers: %HTTPotion.Headers{hdrs: %{"access-control-allow-credentials" => "true",
    "access-control-allow-origin" => "*", "connection" => "keep-alive",
    "content-length" => "176", "content-type" => "application/json",
    "date" => "Sat, 11 Feb 2017 02:47:51 GMT", "server" => "nginx"}},
 status_code: 200}
@mikepc
Copy link

mikepc commented Sep 20, 2017

Right now I'm looking at the documentation and online resources and I'm seeing this exact problem and figuring out what the exact syntax is to set headers to make a get request, it's more challenging than it should be, and the documentation needs to be updated so that newcomers know how to use the tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants