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

Clean rebased version of https-proxy #170

Merged
merged 32 commits into from
Aug 1, 2013
Merged

Clean rebased version of https-proxy #170

merged 32 commits into from
Aug 1, 2013

Conversation

schlamar
Copy link
Contributor

@schlamar schlamar commented Apr 5, 2013

This is a cleaned up version of #139 rebased against current master.

Current todo:

All discussions in the diff

Other

@Lukasa
Copy link
Sponsor Contributor

Lukasa commented Apr 23, 2013

Is there anything I can do to help keep this moving along, @shazow? I appreciate you have lots of pressure on your time, so if there's anything you'd like me to do please say. =)

@shazow
Copy link
Member

shazow commented Apr 23, 2013

Hm so what's the status of this? Is it ready to be considered for merging again?

I'm still seeing a bunch of # TODO's, is that intended?

Anyone familiar with software copyright/licenses have insight on whether it's a problem to introduce separately licensed submodules into the main codebase? (dummyserver/proxy.py) Should we try to consolidate the licenses?

@Anorov
Copy link

Anorov commented Apr 23, 2013

The only TODO of significance left is the "proxy authentication" one, I think.

Personally I think all proxy auth should be handled in the URL, with maybe an alternate option of passing it into the proxy_headers constructor parameter. That is, https://username:password@proxy.com. The username and password can then be accessed from self.proxy.auth, since it is urlparsed.

How is basic auth handled normally? I see a make_headers function in util.py but it doesn't seem to be used within the library itself.

@shazow
Copy link
Member

shazow commented Apr 24, 2013

urllib3's level of abstraction does not hide headers from the user. The user is responsible for making headers, such as by using make_headers.

@schlamar
Copy link
Contributor Author

schlamar commented May 3, 2013

Anyone familiar with software copyright/licenses have insight on whether it's a problem to introduce separately licensed submodules into the main codebase? (dummyserver/proxy.py) Should we try to consolidate the licenses?

This is exactly the same thing than the vendored libraries in packages or I am missing something?!

I'm still seeing a bunch of # TODO's, is that intended?

The first TODO is proposing an optimization in a backward compatibility branch, this can be ignored/dropped.

Basic proxy authorization looks pretty simple (from urllib2):

    if user and password:
        user_pass = '%s:%s' % (unquote(user), unquote(password))
        creds = base64.b64encode(user_pass).strip()
        req.add_header('Proxy-authorization', 'Basic ' + creds)

But I guess we should have a proper way to test this?

@kislyuk
Copy link

kislyuk commented May 5, 2013

@shazow Please please please can this be merged? This makes requests work with https proxies, and doesn't break anything that we could detect. But since no version of requests or urllib3 on pypi carries this patchset, we have to vendor requests+urllib3 with it applied.

@@ -171,12 +177,20 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
:param headers:
Headers to include with all requests, unless other headers are given
explicitly.

:param proxy:
Copy link
Member

Choose a reason for hiding this comment

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

Since these params are "internal", should we prefix them with an underscore? _proxy and _proxy_headers.

Honestly I'm not a huge fan of having them here, but I can't think of a better solution right now.

@shazow
Copy link
Member

shazow commented May 5, 2013

Hey @kislyuk and fellow Andrey.

My apologies, this has been a very long-lived issue and has been a lot of work to get right. We're almost there, though. This branch looks very close but it may still be some time until it's merged and published.

If you'd like to help, more reviews of this code would be appreciated, and any additional tests you can add are always helpful too.

Alternatively, you can campaign for @kennethreitz to maintain a vendored version of urllib3 with this merged in, but that might be a hard sell. :)

@schlamar Thanks for all of your work so far! Could you also rebase this branch on the latest master when you have a chance?

@schlamar
Copy link
Contributor Author

schlamar commented May 6, 2013

@shazow Done.

@stanvit You can commit the proposed changes to #139, then I'll cherry-pick them from there into this branch.

@schlamar
Copy link
Contributor Author

Some failing tests on Windows, someone any idea: https://gist.github.com/schlamar/03b01c41bab64ed02bbf

@schlamar
Copy link
Contributor Author

I have updated my automatic test script with the latest rebased versions of urllib3 and requests. Everyone with a proxy environment should give it a try: https://gist.github.com/schlamar/5080598

@schlamar
Copy link
Contributor Author

Things to address (AFAIS). These are links to specific comments:

Edit: Ping @shazow Anything else?

@Lukasa
Copy link
Sponsor Contributor

Lukasa commented Jul 19, 2013

I can try taking a look at some of the windows stuff this evening if no-one gets around to it before me.

@t-8ch
Copy link
Contributor

t-8ch commented Jul 19, 2013

The test is failing, because the response returned by the dummy_server is missing the Reason-Phrase.
(This is checked in tornado/simple_httpclient:_HTTPConnection:_on_headers())

Changing the status of the response returned from dummyserver/handlers.py:TestingApp:redirect() to include this phrase (303 See Other) fixes this.

See #205.

@schlamar
Copy link
Contributor Author

Ah, I guess this is only an issue for Tornado >= 3. Should fix my test dependencies...

@shazow
Copy link
Member

shazow commented Jul 19, 2013

@schlamar Your list sounds about right. Added it as a check list to the bug description.

@t-8ch
Copy link
Contributor

t-8ch commented Jul 19, 2013

@shazow Last TODO is fixed. (failing test)

@t-8ch
Copy link
Contributor

t-8ch commented Jul 19, 2013

#208 fixes the bug about SSL not being available. (second TODO)

@hjwp
Copy link

hjwp commented Jul 22, 2013

Just +1'ing in order to track the issue. Sounds like this has been going for a long time, well done to everyone involved, keep your spirits up, and thanks for all the hard work!

@schlamar
Copy link
Contributor Author

New rebase against master.

@stanvit I revoked your write access because I'm back from vacation. Please send your changes as pull request against my proxy-rebase-fix branch. I often do history rewrites so this would be nasty if we two write in parallel to the same branch (I already had to clean up your merge commit).

@schlamar
Copy link
Contributor Author

Updated the todo list.

@shazow Last two points are waiting for your answer :)

@schlamar
Copy link
Contributor Author

@stanvit I stripped out this commit in favor of this one. I assume they have the same goal, right?

@shazow
Copy link
Member

shazow commented Jul 31, 2013

I'm satisfied. :) Is this it for everyone?

@schlamar
Copy link
Contributor Author

Ship it 👍

@@ -145,7 +149,10 @@ def urlopen(self, method, url, redirect=True, **kw):
if 'headers' not in kw:
kw['headers'] = self.headers

response = conn.urlopen(method, u.request_uri, **kw)
if self.proxy is not None and u.scheme == "http":
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining this condition?

Also would it be better to just set url = u.request_uri rather than fork the whole line?

@shazow
Copy link
Member

shazow commented Jul 31, 2013

Couple of minor style requests, otherwise ready to merge. :)

shazow added a commit that referenced this pull request Aug 1, 2013
@shazow shazow merged commit 14b8945 into urllib3:master Aug 1, 2013
@shazow
Copy link
Member

shazow commented Aug 1, 2013

You guys are amazing, thank you all. ✨

@schlamar schlamar deleted the proxy-rebase-fix branch August 1, 2013 20:01
shazow added a commit that referenced this pull request Aug 1, 2013
@koobs
Copy link

koobs commented Aug 2, 2013

🏁 SHIP IT BABY! 🏁 - Great effort all

@stanvit
Copy link
Contributor

stanvit commented Aug 2, 2013

Thank you everybody for pushing this!

@JakeAustwick
Copy link

Is it possible this isn't passing auth details along? After applying the above patch I am getting:
requests.packages.urllib3.exceptions.ProxyError: Cannot connect to proxy. Socket error: Tunnel connection failed: 407 Proxy Authentication Required.

Before the patch I was getting:
requests.exceptions.HTTPError: 501 Server Error: Not Implemented

@schlamar
Copy link
Contributor Author

Is it possible this isn't passing auth details along?

Yes, proxy auth is still missing.

@JakeAustwick
Copy link

Is there anyway I can make this work, by passing in the headers manually or something? Or is it simply not supported right now?

@schlamar
Copy link
Contributor Author

Is there anyway I can make this work, by passing in the headers manually or something?

This should work I guess :)

But please create a new ticket to request proxy auth support.

@stanvit
Copy link
Contributor

stanvit commented Aug 14, 2013

Proxy authentication is working for me on the low level: the Proxy-Authorization header should be supplied in proxy_headers:

>>> from urllib3.poolmanager import ProxyManager
>>> goodauth = ProxyManager('http://localhost:3128', proxy_headers={'Proxy-Authorization': 'Basic dGVzdDp0ZXN0'})
>>> goodauth.request('GET', 'https://httpbin.org/get').status
200
>>> goodauth.request('GET', 'http://httpbin.org/get').status
200
>>> badauth = ProxyManager('http://localhost:3128', proxy_headers={'Proxy-Authorization': 'Basic garbage'})
>>> badauth.request('GET', 'https://httpbin.org/get').status
Traceback (most recent call last):
...
urllib3.exceptions.ProxyError: Cannot connect to proxy. Socket error: Tunnel connection failed: 407 Proxy Authentication Required.
>>> badauth.request('GET', 'http://httpbin.org/get').status
407

@shazow
Copy link
Member

shazow commented Aug 14, 2013

Would be awesome to get some examples like that into the docs, if anyone wants to do a PR. :)

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.

None yet