Return the HTTP host using the environment or request headers. Skip allowed hosts protection, so may return an insecure host.
(self)
| 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.""" |
no test coverage detected