diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-14 05:28:00 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-14 05:28:00 +0000 |
| commit | e70d7e60640e280f8d410d41c1f9cb6195483c4e (patch) | |
| tree | 601a16030a28d5709f3dfbfe87db8a82f596e03f /django/http | |
| parent | dc785104b8ffb33c57f5e17209743516c1bd88ae (diff) | |
Fixed #987 -- Convert relative URI portions into absolute URIs in HTTP Location headers. Based on a patch from SmileyChris.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6164 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/__init__.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index 20818f138b..74764690a3 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -2,6 +2,7 @@ import os from Cookie import SimpleCookie from pprint import pformat from urllib import urlencode +from urlparse import urljoin from django.utils.datastructures import MultiValueDict, FileDict from django.utils.encoding import smart_str, iri_to_uri, force_unicode @@ -42,10 +43,24 @@ class HttpRequest(object): return key in self.GET or key in self.POST __contains__ = has_key - + def get_full_path(self): return '' + def build_absolute_uri(self, location=None): + """ + Builds an absolute URI from the location and the variables available in + this request. If no location is specified, the absolute URI is built on + ``request.get_full_path()``. + """ + if not location: + location = request.get_full_path() + if not ':' in location: + current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http', + get_host(self), self.path) + location = urljoin(current_uri, location) + return location + def is_secure(self): return os.environ.get("HTTPS") == "on" |
