Author: mtredinnick
Date: 2007-09-14 00:39:42 -0500 (Fri, 14 Sep 2007)
New Revision: 6166

Modified:
   django/trunk/django/http/__init__.py
Log:
Fixed #4986 -- Improved get_host() host detection. Thanks, SmileyChris.


Modified: django/trunk/django/http/__init__.py
===================================================================
--- django/trunk/django/http/__init__.py        2007-09-14 05:33:39 UTC (rev 
6165)
+++ django/trunk/django/http/__init__.py        2007-09-14 05:39:42 UTC (rev 
6166)
@@ -379,9 +379,16 @@
 
 def get_host(request):
     "Gets the HTTP host from the environment or request headers."
+    # We try three options, in order of decreasing preference.
     host = request.META.get('HTTP_X_FORWARDED_HOST', '')
-    if not host:
-        host = request.META.get('HTTP_HOST', '')
+    if 'HTTP_HOST' in request.META:
+        host = request.META['HTTP_HOST']
+    else:
+        # Reconstruct the host using the algorithm from PEP 333.
+        host = request.META['SERVER_NAME']
+        server_port = request.META['SERVER_PORT']
+        if server_port != (request.is_secure() and 443 or 80):
+            host = '%s:%s' % (host, server_port)
     return host
 
 # It's neither necessary nor appropriate to use


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to