Only send URL path to servers
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Closes #256
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 2ccc68c · Browse files · 1 file·+37 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+37 added−12 removed
- other:+37 added−12 removed
Provenance
- Commit
4504953- Tree
e5a7a3b- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
2ccc68c
1 file changed+37 added−12 removed
modified:requests/models.py+37 added-12 removed
9 unmodified lines10 import urllib11 import zlib12 13 from Cookie import SimpleCookie14-from urlparse import urlparse, urlunparse, urljoin14+from urlparse import urlparse, urlunparse, urljoin, urlsplit15 from datetime import datetime16 17 from .auth import dispatch as auth_dispatch18 from .hooks import dispatch_hook161 unmodified lines180 181 if is_error:182 response.error = resp183 184- response.url = self._build_url()184+ response.url = self.full_url185 186 return response187 188 91 unmodified lines280 return result, urllib.urlencode(result, doseq=True)281 else:282 return data, data283 284-285- def _build_url(self):284+ @property285+ def full_url(self):286 """Build the actual URL to use."""287 288 if not self.url:289 raise URLRequired()9 unmodified lines299 if isinstance(path, unicode):300 path = path.encode('utf-8')301 302 path = urllib.quote(urllib.unquote(path))303- self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))303 304+ url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))305+306 if self._enc_params:306- if urlparse(self.url).query:307- return '%s&%s' % (self.url, self._enc_params)307+ if urlparse(url).query:308+ return '%s&%s' % (url, self._enc_params)309 else:309- return '%s?%s' % (self.url, self._enc_params)310+ return '%s?%s' % (url, self._enc_params)311 else:311- return self.url312+ return url313 314+ @property315+ def path_url(self):316+ """Build the path URL to use."""317 318+ url = []319+320+ p = urlsplit(self.full_url)321+322+ # Proxies use full URLs.323+ if p.scheme in self.proxies:324+ return self.full_url325+326+ path = p.path327+ if not path:328+ path = '/'329+ url.append(path)330+331+ query = p.query332+ if query:333+ url.append('?')334+ url.append(query)335+336+ return ''.join(url)337+338+339+340 def send(self, anyway=False, prefetch=False):341 """Sends the request. Returns True of successful, false if not.342 If there was an HTTPError during transmission,343 self.response.status_code will contain the HTTPError code.10 unmodified lines354 datetime.now().isoformat(), self.method, self.url355 ))356 357 # Build the URL332- url = self._build_url()358+ url = self.full_url359 360 # Nottin' on you.361 body = None362 content_type = None68 unmodified lines431 self.headers['Cookie'] = cookie_header432 433 try:434 # Send the request.409-435 r = conn.urlopen(436 method=self.method,412- url=url,437+ url=self.path_url,438 body=body,439 headers=self.headers,440 redirect=False,441 assert_same_host=False,177 unmodified lines