Skip to content

Commit

Permalink
only enforce host presence for HTTP / HTTPS
Browse files Browse the repository at this point in the history
Requests supports adding other protocols by mounting an adapter for them.  For
protocols that don't require a host entry, this handling is overzealous, and
prevents useful URLs from making it through.  This change only enforces this
for the http and https protocol schemes, and adjusts the rest of the URL
handling to be more friendly to non-present network locations.
  • Loading branch information
jvantuyl committed Oct 29, 2013
1 parent 2e196be commit 90b37b3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,22 @@ def prepare_url(self, url, params):
raise MissingSchema("Invalid URL {0!r}: No schema supplied. "
"Perhaps you meant http://{0}?".format(url))

if not host:
if scheme in ('http', 'https') and not host:
raise InvalidURL("Invalid URL %r: No host supplied" % url)

# Only want to apply IDNA to the hostname
try:
host = host.encode('idna').decode('utf-8')
if host:
host = host.encode('idna').decode('utf-8')
except UnicodeError:
raise InvalidURL('URL has an invalid label.')

# Carefully reconstruct the network location
netloc = auth or ''
if netloc:
netloc += '@'
netloc += host
if host:
netloc += host
if port:
netloc += ':' + str(port)

Expand Down

0 comments on commit 90b37b3

Please sign in to comment.