Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Default proxy scheme to HTTP #1924

Merged
merged 2 commits into from

4 participants

schlamar added some commits
@Lukasa
Collaborator

I am happy enough to take this. =)

@Lukasa
Collaborator

Note that this would have to go into 2.3.0.

@schlamar

@Lukasa I assume this stalled until 2.3 is in sight? Any rough ETA?

@Lukasa
Collaborator

Kenneth is responsible for merging any code change, so he owns this I'm afraid. This will get merged when he has time. =)

@schlamar

Don't you usually assign him to the PR after review so that he knows he can have a look? =)

@Lukasa
Collaborator

Not normally, no. =) But I will, just to make you happy. :cake:

@kennethreitz kennethreitz was assigned by Lukasa
@schlamar

Hehe =) I have just seen this on another PR so I thought this is default...

@sigmavirus24
Collaborator

@schlamar I've been doing this for PRs that need to be merged quickly so they don't get lost. I'll assign it and then comment along the lines "LGTM!" so that Kenneth gets an email (I'm not sure he has emails turned on for every issue/PR). This is just my way of being certain that he receives a notification. :)

@sigmavirus24
Collaborator

Also, LGTM.

@kennethreitz kennethreitz reopened this
@kennethreitz kennethreitz merged commit c023f06 into kennethreitz:master
@schlamar schlamar deleted the schlamar:proxy-default-scheme branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2014
  1. @schlamar

    Revert "Proxy urls should have explicit schemes."

    schlamar authored
    This reverts commit 840540b.
    
    Conflicts:
    	requests/adapters.py
    	requests/utils.py
  2. @schlamar
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 10 deletions.
  1. +2 −2 requests/adapters.py
  2. +13 −8 requests/utils.py
View
4 requests/adapters.py
@@ -16,7 +16,7 @@
from .packages.urllib3.util import Timeout as TimeoutSauce
from .compat import urlparse, basestring, urldefrag, unquote
from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
- except_on_missing_scheme, get_auth_from_url)
+ prepend_scheme_if_needed, get_auth_from_url)
from .structures import CaseInsensitiveDict
from .packages.urllib3.exceptions import MaxRetryError
from .packages.urllib3.exceptions import TimeoutError
@@ -203,7 +203,7 @@ def get_connection(self, url, proxies=None):
proxy = proxies.get(urlparse(url.lower()).scheme)
if proxy:
- except_on_missing_scheme(proxy)
+ proxy = prepend_scheme_if_needed(proxy, 'http')
proxy_headers = self.proxy_headers(proxy)
if not proxy in self.proxy_manager:
View
21 requests/utils.py
@@ -24,10 +24,10 @@
from . import certs
from .compat import parse_http_list as _parse_list_header
from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2,
- builtin_str, getproxies, proxy_bypass)
+ builtin_str, getproxies, proxy_bypass, urlunparse)
from .cookies import RequestsCookieJar, cookiejar_from_dict
from .structures import CaseInsensitiveDict
-from .exceptions import MissingSchema, InvalidURL
+from .exceptions import InvalidURL
_hush_pyflakes = (RequestsCookieJar,)
@@ -622,13 +622,18 @@ def guess_json_utf(data):
return None
-def except_on_missing_scheme(url):
- """Given a URL, raise a MissingSchema exception if the scheme is missing.
- """
- scheme, netloc, path, params, query, fragment = urlparse(url)
+def prepend_scheme_if_needed(url, new_scheme):
+ '''Given a URL that may or may not have a scheme, prepend the given scheme.
+ Does not replace a present scheme with the one provided as an argument.'''
+ scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)
+
+ # urlparse is a finicky beast, and sometimes decides that there isn't a
+ # netloc present. Assume that it's being over-cautious, and switch netloc
+ # and path if urlparse decided there was no netloc.
+ if not netloc:
+ netloc, path = path, netloc
- if not scheme:
- raise MissingSchema('Proxy URLs must have explicit schemes.')
+ return urlunparse((scheme, netloc, path, params, query, fragment))
def get_auth_from_url(url):
Something went wrong with that request. Please try again.