Ejemplo n.º 1
0
    def port(self):
        try:
            host_header = self.env['HTTP_HOST']
            default_port = 80 if self.env['wsgi.url_scheme'] == 'http' else 443
            host, port = parse_host(host_header, default_port=default_port)
        except KeyError:
            # PEP-3333 requires that the port never be an empty string.
            port = int(self.env['SERVER_PORT'])

        return port
Ejemplo n.º 2
0
    def host(self):
        try:
            host_header = self.env['HTTP_HOST']
            host, port = parse_host(host_header)
        except KeyError:
            # According to PEP-3333, this header
            # will always be present.
            host = self.env['SERVER_NAME']

        return host
Ejemplo n.º 3
0
    def access_hops(self):
        if self._cached_access_hops is None:
            if 'HTTP_FORWARDED' in self.env:
                self._cached_access_hops = []
                for hop in self.forwarded:
                    if hop.src is not None:
                        host, __ = parse_host(hop.src)
                        self._cached_access_hops.append(host)
            elif 'HTTP_X_FORWARDED_FOR' in self.env:
                addresses = self.env['HTTP_X_FORWARDED_FOR'].split(',')
                self._cached_access_hops = [ip.strip() for ip in addresses]
            elif 'HTTP_X_REAL_IP' in self.env:
                self._cached_access_hops = [self.env['HTTP_X_REAL_IP']]
            elif 'REMOTE_ADDR' in self.env:
                self._cached_access_hops = [self.env['REMOTE_ADDR']]
            else:
                self._cached_access_hops = []

        return self._cached_access_hops