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

properly handle URLs that already contain a query string #223

Merged
merged 2 commits into from
Mar 4, 2017

Conversation

jadlr
Copy link
Contributor

@jadlr jadlr commented Feb 15, 2017

before this, URLs that already contain a query string were not handled.

iex(3)> HTTPoison.get("https://httpbin.org/get?yolo=bolo", [], params: %{whut: "hello"})
{:ok,
 %HTTPoison.Response{body: "{\n  \"args\": {\n    \"yolo\": \"bolo?whut=hello\"\n  }, \n  \"headers\": {\n    \"Host\": \"httpbin.org\", \n    \"User-Agent\": \"hackney/1.6.5\"\n  }, \n  \"origin\": \"193.240.195.178\", \n  \"url\": \"https://httpbin.org/get?yolo=bolo%3Fwhut=hello\"\n}\n",
  headers: [{"Server", "nginx"}, {"Date", "Thu, 16 Feb 2017 10:29:15 GMT"},
   {"Content-Type", "application/json"}, {"Content-Length", "225"},
   {"Connection", "keep-alive"}, {"Access-Control-Allow-Origin", "*"},
   {"Access-Control-Allow-Credentials", "true"}], status_code: 200}}

note that the URL used was https://httpbin.org/get?yolo=bolo%3Fwhut=hello not https://httpbin.org/get?yolo=bolo&whut=hello

@jadlr
Copy link
Contributor Author

jadlr commented Feb 21, 2017

This is a little more complex than I initially thought. Parameters should not be overwritten since a query string can contain a key multiple times.

EDIT: added a commit that fixes this

@edgurgel
Copy link
Owner

Thanks for the PR. I will have look soon. Sorry for the delay to give feedback

@jadlr
Copy link
Contributor Author

jadlr commented Feb 21, 2017

No worries, thanks for considering it!

else
url
end
cond do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are now 3 cases here. I suspect we should have now 3 tests (1 for each case) right? How can we reach the true case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the true case is reached in the get with params test. The second condition is reached in the test I added and the first condition is reached in the get test. Maybe cond do isn't the best choice here, do you want me to change it into a nested if else?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Thanks for the explanation. Hmm I think cond is fine!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome!

@edgurgel edgurgel merged commit d7633d7 into edgurgel:master Mar 4, 2017
@edgurgel
Copy link
Owner

edgurgel commented Mar 4, 2017

Thanks! I'm sorry for the delay 😶

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

Successfully merging this pull request may close these issues.

2 participants