-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Support HTTP proxy (username, password) authentication #100
base: master
Are you sure you want to change the base?
Conversation
echo the Proxy-Authorization header back (which is expectedly in-line with the specs)
case basic: RequestAuth.Basic => | ||
connection.setRequestProperty("Authorization", basic.credentials.get) | ||
case bearer: RequestAuth.Bearer => | ||
connection.setRequestProperty("Authorization", bearer.credentials.get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 236 and 238 are doing the same thing, maybe we can use case Foo | Bar
to handle them both together in the same case
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to tweak my implementation. Would appreciate any feedback you have on the latest round of changes :)
I've updated this to introduce a (tl;dr this removes It's also worth noting that python-requests implements proxy auth through a connection URL ( Tested locally: // No proxy:
requests.get("http://httpbin.org/ip").text()
// => { "origin": "my_ip" }
// Auth required:
requests.get("http://httpbin.org/ip", proxy=("proxy.provider.com", 8011))
// => requests.RequestFailedException: Request to http://httpbin.org/ip failed with status code 407
// Incorrect auth:
requests.get("http://httpbin.org/ip", proxy=("proxy.provider.com", 8011), proxyAuth=("blah", ""))
// => requests.RequestFailedException: Request to http://httpbin.org/ip failed with status code 407
// Ok, proxied:
requests.get("http://httpbin.org/ip", proxy=("proxy.provider.com", 8011), proxyAuth=("user", "pass")).text()
// => { "origin": "proxy_ip" } I also noticed that the JVM is removing the @lihaoyi let me know if you'd like credentials to a proxy service to reproduce/test this further edit: fixes #79 |
I noticed that the
Proxy-Authorization
header was being inserted as a value in theAuthorization: ..
header when usingRequestAuth.Proxy(..)
.requests.RequestAuth.Proxy
:nc
:Proxy-Authorization
is a standalone header [0], and should not be passed inAuthorization
.This PR fixes it by replacing
RequestAuth.header
with aRequestAuth.credentials
that returns the built credential to be passed as a header value into the connection. In the Requester, it performs a match onRequestAuth.{TYPE}
to determine the header key/value to set.Unfortunately, I'm unable to get unit tests for proxy auth working - most services similar to httpbin (including it) doesn't echo the
Proxy-Authorization
value back, according to specs [1] [2]. We can spin up a local http server within the test environment to echo stuff back, though (it'd also reduce CI runtime if it no longer relies on external network requests). I'll leave that to you folks; for now I've commented out the test case and left some notes in there - if you switch to a locally-managed test env, uncommenting and pointing the request to the internal service should make the test pass :)I manually tested the proxy auth portion against localhost:
[0] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization
[1] https://tools.ietf.org/html/rfc7235#section-4.4
[2] postmanlabs/httpbin#465
(p/s: I'm very new to Scala, would really love any and all feedback - thank you!)