MCPcopy
hub / github.com/django/django / _get_raw_host

Method _get_raw_host

django/http/request.py:172–188  ·  view source on GitHub ↗

Return the HTTP host using the environment or request headers. Skip allowed hosts protection, so may return an insecure host.

(self)

Source from the content-addressed store, hash-verified

170 self.encoding = self.content_params["charset"]
171
172 def _get_raw_host(self):
173 """
174 Return the HTTP host using the environment or request headers. Skip
175 allowed hosts protection, so may return an insecure host.
176 """
177 # We try three options, in order of decreasing preference.
178 if settings.USE_X_FORWARDED_HOST and ("HTTP_X_FORWARDED_HOST" in self.META):
179 host = self.META["HTTP_X_FORWARDED_HOST"]
180 elif "HTTP_HOST" in self.META:
181 host = self.META["HTTP_HOST"]
182 else:
183 # Reconstruct the host using the algorithm from PEP 333.
184 host = self.META["SERVER_NAME"]
185 server_port = self.get_port()
186 if server_port != ("443" if self.is_secure() else "80"):
187 host = "%s:%s" % (host, server_port)
188 return host
189
190 def get_host(self):
191 """Return the HTTP host using the environment or request headers."""

Callers 2

get_hostMethod · 0.95
_get_raw_insecure_uriMethod · 0.80

Calls 2

get_portMethod · 0.95
is_secureMethod · 0.95

Tested by

no test coverage detected