From ad25bcc2be752c034d974fdc3cf9ad1a70257bb5 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 24 May 2011 05:26:51 +0000 Subject: [PATCH] better way for dealing with relative paths --- lib/request/connect.py | 3 +++ lib/request/redirecthandler.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/request/connect.py b/lib/request/connect.py index b8212b9ca..f0cfcb0f9 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -104,6 +104,9 @@ class Connect: retrying = kwargs.get('retrying', False) redirecting = kwargs.get('redirecting', False) + if not urlparse.urlsplit(url).netloc: + url = urlparse.urljoin(conf.url, url) + # flag to know if we are dealing with the same target host target = reduce(lambda x, y: x == y, map(lambda x: urlparse.urlparse(x).netloc.split(':')[0], [url, conf.url])) diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index 8a1e22e14..cce841877 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -54,7 +54,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): result.redurl = headers.getheaders("uri")[0].split("?")[0] if hasattr(result, 'redurl'): - if result.redurl.startswith('.') or result.redurl.startswith('/'): + if not urlparse.urlsplit(result.redurl).netloc: result.redurl = urlparse.urljoin(conf.url, result.redurl) if "set-cookie" in headers: