예제 #1
0
    def get_real_client_addr(self):
        ip = self.request.headers.get('X-Real-Ip')
        port = self.request.headers.get('X-Real-Port')

        if ip is None and port is None:  # suppose the server doesn't use nginx
            return

        if is_valid_ipv4_address(ip) or is_valid_ipv6_address(ip):
            try:
                port = int(port)
            except (TypeError, ValueError):
                pass
            else:
                if is_valid_port(port):
                    return (ip, port)

        logging.warning('Bad nginx configuration.')
        return False
예제 #2
0
 def test_is_valid_ipv6_address(self):
     self.assertFalse(is_valid_ipv6_address('abc'))
     self.assertFalse(is_valid_ipv6_address(b'abc'))
     self.assertTrue(is_valid_ipv6_address('::1'))
     self.assertTrue(is_valid_ipv6_address(b'::1'))
예제 #3
0
 def get_hostname(self):
     value = self.get_value('hostname')
     if not (is_valid_hostname(value) | is_valid_ipv4_address(value)
             | is_valid_ipv6_address(value)):
         raise InvalidException('Invalid hostname: {}'.format(value))
     return value
예제 #4
0
 def get_hostname(self):
     value = self.get_value('hostname')
     if not (is_valid_hostname(value) | is_valid_ipv4_address(value)
             | is_valid_ipv6_address(value)):
         raise ValueError('Invalid hostname: {}.'.format(value))
     return value