Ticket #4986: get_host.patch

File get_host.patch, 854 bytes (added by Chris Beaven, 17 years ago)
  • django/http/__init__.py

     
    356356
    357357def get_host(request):
    358358    "Gets the HTTP host from the environment or request headers."
    359     host = request.META.get('HTTP_X_FORWARDED_HOST', '')
     359    host = (request.META.get('HTTP_X_FORWARDED_HOST')
     360            or request.META.get('HTTP_HOST'))
    360361    if not host:
    361         host = request.META.get('HTTP_HOST', '')
     362        # Reconstruct host based on PEP333
     363        host = request.META['SERVER_NAME']
     364        server_port = request.META['SERVER_PORT']
     365        if server_port != (request.is_secure() and 443 or 80):
     366            host = '%s:%s' % (host, server_port)
    362367    return host
    363368
    364369# It's neither necessary nor appropriate to use
Back to Top