code: def get_host(request):
      
      # We try three options, in order of decreasing preference.
      if settings.USE_X_FORWARDED_HOST and (
              'HTTP_X_FORWARDED_HOST' in request.META):
          host = request.META['HTTP_X_FORWARDED_HOST']
      elif '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 = str(request.META['SERVER_PORT'])
          if server_port != (request.is_secure() and '443' or '80'):
              host = '%s:%s' % (host, server_port)
      return host
docs: A reimplementation of Django's get_host, without the
      SuspiciousOperation check.