diff options
| author | Vlastimil Zíma <vlastimil.zima@gmail.com> | 2015-09-03 20:52:49 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-09-04 09:24:21 -0400 |
| commit | cf29b6b5610f242d18dcc31eb897c873109b67e2 (patch) | |
| tree | bd60ca9d686cd22a002e7a2e2f3d4ab288c1d9eb /django/http | |
| parent | 4c0447b2ae57f4e8c44bcb2f371d160cb8daa930 (diff) | |
Fixed #25099 -- Fixed crash in AdminEmailHandler on DisallowedHost.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/request.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/django/http/request.py b/django/http/request.py index b50392abd2..15f1c4614e 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -68,8 +68,11 @@ class HttpRequest(object): '<%s: %s %r>' % (self.__class__.__name__, self.method, force_str(self.get_full_path())) ) - def get_host(self): - """Returns the HTTP host using the environment or request headers.""" + def _get_raw_host(self): + """ + Return the HTTP host using the environment or request headers. Skip + allowed hosts protection, so may return an insecure host. + """ # We try three options, in order of decreasing preference. if settings.USE_X_FORWARDED_HOST and ( 'HTTP_X_FORWARDED_HOST' in self.META): @@ -82,6 +85,11 @@ class HttpRequest(object): server_port = self.get_port() if server_port != ('443' if self.is_secure() else '80'): host = '%s:%s' % (host, server_port) + return host + + def get_host(self): + """Return the HTTP host using the environment or request headers.""" + host = self._get_raw_host() # There is no hostname validation when DEBUG=True if settings.DEBUG: @@ -138,6 +146,17 @@ class HttpRequest(object): raise return value + def get_raw_uri(self): + """ + Return an absolute URI from variables available in this request. Skip + allowed hosts protection, so may return insecure URI. + """ + return '{scheme}://{host}{path}'.format( + scheme=self.scheme, + host=self._get_raw_host(), + path=self.get_full_path(), + ) + def build_absolute_uri(self, location=None): """ Builds an absolute URI from the location and the variables available in |
