Example #1
0
def getHostname(data=None):
    """Returns the hostname (taking into account site hostname settings).

  Args:
    data: A RequestData object.

  Returns:
    The site hostname.
  """
    settings = data.site if data else singleton()
    return settings.hostname if settings.hostname else system.getRawHostname()
Example #2
0
  def testGetRawHostName(self):
    """Tests that a correct raw host name is returned."""
    try:
      host = os.environ['HTTP_HOST'] = 'some.testing.host.tld'
      expected_current_host = host
      self.assertEqual(system.getRawHostname(), expected_current_host)
    finally:
      if self.default_host is None:
        del os.environ['HTTP_HOST']
      else:
        os.environ['HTTP_HOST'] = self.default_host

    try:
      expected_host = os.environ['HTTP_HOST'] = ''
      self.assertEqual(system.getRawHostname(), expected_host)
    finally:
      if self.default_host is None:
        del os.environ['HTTP_HOST']
      else:
        os.environ['HTTP_HOST'] = self.default_host
Example #3
0
def getHostname(data=None):
  """Returns the hostname (taking into account site hostname settings).

  Args:
    data: A RequestData object.

  Returns:
    The site hostname.
  """
  settings = data.site if data else singleton()
  return settings.hostname if settings.hostname else system.getRawHostname()
Example #4
0
    def testGetRawHostName(self):
        """Tests that a correct raw host name is returned."""
        try:
            host = os.environ['HTTP_HOST'] = 'some.testing.host.tld'
            expected_current_host = host
            self.assertEqual(system.getRawHostname(), expected_current_host)
        finally:
            if self.default_host is None:
                del os.environ['HTTP_HOST']
            else:
                os.environ['HTTP_HOST'] = self.default_host

        try:
            expected_host = os.environ['HTTP_HOST'] = ''
            self.assertEqual(system.getRawHostname(), expected_host)
        finally:
            if self.default_host is None:
                del os.environ['HTTP_HOST']
            else:
                os.environ['HTTP_HOST'] = self.default_host
Example #5
0
def isSecondaryHostname(data=None):
    """Identifies if the current request is from the secondary hostname.

  Args:
    data: A RequestData object.

  Returns:
    True if the current request is from the secondary hostname; False
      otherwise.
  """
    settings = data.site if data else singleton()
    return settings.hostname and settings.hostname in system.getRawHostname()
Example #6
0
def isSecondaryHostname(data=None):
  """Identifies if the current request is from the secondary hostname.

  Args:
    data: A RequestData object.

  Returns:
    True if the current request is from the secondary hostname; False
      otherwise.
  """
  settings = data.site if data else singleton()
  return settings.hostname and settings.hostname in system.getRawHostname()