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

Getting an exception when following redirects #131

Open
alex0112 opened this issue Jul 23, 2019 · 1 comment
Open

Getting an exception when following redirects #131

alex0112 opened this issue Jul 23, 2019 · 1 comment

Comments

@alex0112
Copy link

alex0112 commented Jul 23, 2019

Making a GET request on a URI that follows redirects like so:

 payload = [
      body: "",
      follow_redirects: true,
      headers:
      [
        "...": ...,
        "Content-Type": "application/json",
      ]
    ]

HTTPotion.get "api.example.com/path/to/resource", payload

Produces an ArgumentException from the URI module:

** (ArgumentError) you must merge onto an absolute URI
    (elixir) lib/uri.ex:518: URI.merge/2
    (httpotion) lib/httpotion.ex:455: HTTPotion.normalize_location/2
    (httpotion) lib/httpotion.ex:455: HTTPotion.request/3
    (project) lib/file.ex:60: File.function/1

Specifically this exception occurs when I send an authenticated request to the Coinbase accounts endpoint.

I'm admittedly new to both Elixir and this library: but I suspect this error is being caused because the Coinbase API is returning an odd URI string which HTTPotion's normalize_location/2 function calls URI.merge/2 with the odd URI from the redirect, which is constructed without prepending http[s]:// to the URI. This causes the authority key in the URI struct to end up nil, meaning that URI.merge/2 is the specific version of the function being called. I'm trying to dig into the library a bit more to find out how to print the exact URI string that's being returned from the redirect.

This hasn't happened for the other Coinbase calls (this function for example), my suspicion is that when HTTPotion follows a redirect, the resulting string that URI is expected to parse is formed in a way that URI/HTTPotion doesn't expect.

If this isn't expected behavior, I'd like to submit a PR to prevent this exception from being thrown. Otherwise, guidance is appreciated.

@valpackett
Copy link
Owner

how to print the exact URI string that's being returned from the redirect

Just IO.inspect the arguments to URI.merge.

It's merging against the current request URI.. I'm not sure how that ended up not being absolute.

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