Exemplo n.º 1
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            return self.wfile.write(('HTTP/1.1 301\r\nContent-Length: 0\r\n\r\n').encode())

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 2
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            return self.wfile.write(('HTTP/1.1 301\r\nContent-Length: 0\r\n\r\n').encode())

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            return self.forward_local()

        if host_ip == config.get_listen_ip():
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 3
0
    def do_METHOD(self):
        touch_active()
        # record active time.
        # backgroud thread will stop keep connection pool if no request for long time.

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controler = web_control.ControlHandler(self.client_address, self.headers, self.command, self.path, self.rfile, self.wfile)
            if self.command == "GET":
                return controler.do_GET()
            elif self.command == "POST":
                return controler.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        
        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            #xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()
        
        go_proxy = need_proxy_http.proxy(host)
        if not go_proxy:
            xlog.debug("[NOT PROXY]%s", self.path)
            return self.forward_local()
            
        if host_ip in socket.gethostbyname_ex(socket.gethostname())[-1]:
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        if self.path == "http://www.twitter.com/xxnet":
            xlog.debug("%s %s", self.command, self.path)
            # for web_ui status page
            # auto detect browser proxy setting is work
            return self.wfile.write(self.self_check_response_data)

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        # redirect http request to https request
        # avoid key word filter when pass through GFW
        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 4
0
    def do_METHOD(self):
        if self.path != "%s:443" % self.fake_host:
            touch_active()
        # record active time.
        # backgroud thread will stop keep connection pool if no request for long time.

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controller = web_control.ControlHandler(self.client_address,
                                                    self.headers, self.command,
                                                    self.path, self.rfile,
                                                    self.wfile)
            if self.command == "GET":
                return controller.do_GET()
            elif self.command == "POST":
                return controller.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if self.is_local([host, host_ip]):
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        if host == self.fake_host:
            #if self.path == "http://%s/xxnet" % self.fake_host:
            xlog.debug("%s %s", self.command, self.path)
            # for web_ui status page
            # auto detect browser proxy setting is work
            return self.wfile.write(self.self_check_response_data)

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        # redirect http request to https request
        # avoid key word filter when pass through GFW
        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(
                config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 5
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controler = web_control.ControlHandler(self.client_address,
                                                   self.headers, self.command,
                                                   self.path, self.rfile,
                                                   self.wfile)
            if self.command == "GET":
                return controler.do_GET()
            elif self.command == "POST":
                return controler.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            #xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        if host_ip in socket.gethostbyname_ex(socket.gethostname())[-1]:
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        if self.path == "http://www.twitter.com/xxnet":
            xlog.debug("%s %s", self.command, self.path)
            # for web_ui status page
            # auto detect browser proxy setting is work
            return self.wfile.write(self.self_check_response_data)

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(
                config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 6
0
    def dispatch_request(self):
        if self.host == "www.twitter.com" and self.path == "/xxnet":
            xlog.debug("%s %s", self.command, self.url)
            # for web_ui status page
            # auto detect browser proxy setting is work
            return self.wfile.write(self.self_check_response_data)

        if self.host in self_host:
            if self.port == config.LISTEN_PORT:
                controller = web_control.ControlHandler(
                    self.client_address, self.headers, self.command, self.path, self.rfile, self.wfile
                )
                if self.command == "GET":
                    return controller.do_GET()
                elif self.command == "POST":
                    return controller.do_POST()
                else:
                    xlog.warn("method not defined: %s", self.command)
                    return
            else:
                # xlog.warn("Your browser forward localhost to proxy.")
                return self.forward_local()

        touch_active()
        # record active time.
        # backgroud thread will stop keep connection pool if no request for long time.

        if self.host == "www.google.com" and (
            self.path.startswith("/search?") or self.path.startswith("/complete/search?")
        ):
            pass
            # return self.use_DIRECT()

        if self.host in config.HOSTS_GAE or self.host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.use_GAE()

        # redirect http request to https request
        # avoid key word filter when pass through GFW
        if self.host in config.HOSTS_DIRECT or self.host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            if self.method == "http":
                return self.wfile.write(
                    (
                        "HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n"
                        % self.path.replace("http://", "https://", 1)
                    ).encode()
                )
            else:
                return self.use_DIRECT()

        return self.use_GAE()
Exemplo n.º 7
0
    def do_CONNECT(self):
        touch_active()
        host, _, port = self.path.rpartition(':')

        if host in config.HOSTS_GAE:
            return self.do_CONNECT_AGENT()
        if host in config.HOSTS_DIRECT:
            return self.do_CONNECT_DIRECT()

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_CONNECT_AGENT()
        if host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.do_CONNECT_DIRECT()

        return self.do_CONNECT_AGENT()
Exemplo n.º 8
0
 def request(self, method, host, path, headers, body, url="", timeout=60):
     connect_control.touch_active()
     # xlog.debug("task start request")
     if not url:
         url = "%s %s%s" % (method, host, path)
     self.last_request_time = time.time()
     q = Queue.Queue()
     task = http_common.Task(method, host, path, headers, body, q, url, timeout)
     task.set_state("start_request")
     self.request_queue.put(task)
     # self.working_tasks[task.unique_id] = task
     response = q.get(True)
     task.set_state("get_response")
     # del self.working_tasks[task.unique_id]
     return response
Exemplo n.º 9
0
    def do_CONNECT(self):
        touch_active()
        host, _, port = self.path.rpartition(':')

        if host in config.HOSTS_GAE:
            return self.do_CONNECT_AGENT()
        if host in config.HOSTS_DIRECT:
            return self.do_CONNECT_DIRECT()

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_CONNECT_AGENT()
        if host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.do_CONNECT_DIRECT()

        return self.do_CONNECT_AGENT()
Exemplo n.º 10
0
    def dispatch_request(self):
        if self.host == "www.twitter.com" and self.path == "/xxnet":
            xlog.debug("%s %s", self.command, self.url)
            # for web_ui status page
            # auto detect browser proxy setting is work
            return self.wfile.write(self.self_check_response_data)

        if self.host in self_host:
            if self.port == config.LISTEN_PORT:
                controller = web_control.ControlHandler(
                    self.client_address, self.headers, self.command, self.path,
                    self.rfile, self.wfile)
                if self.command == "GET":
                    return controller.do_GET()
                elif self.command == "POST":
                    return controller.do_POST()
                else:
                    xlog.warn("method not defined: %s", self.command)
                    return
            else:
                # xlog.warn("Your browser forward localhost to proxy.")
                return self.forward_local()

        touch_active()
        # record active time.
        # backgroud thread will stop keep connection pool if no request for long time.

        if self.host == "www.google.com" and \
                (self.path.startswith("/search?") or self.path.startswith("/complete/search?") ):
            pass
            #return self.use_DIRECT()

        if self.host in config.HOSTS_GAE or self.host.endswith(
                config.HOSTS_GAE_ENDSWITH):
            return self.use_GAE()

        # redirect http request to https request
        # avoid key word filter when pass through GFW
        if self.host in config.HOSTS_DIRECT or self.host.endswith(
                config.HOSTS_DIRECT_ENDSWITH):
            if self.method == "http":
                return self.wfile.write((
                    'HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n'
                    % self.path.replace('http://', 'https://', 1)).encode())
            else:
                return self.use_DIRECT()

        return self.use_GAE()
Exemplo n.º 11
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controler = web_control.ControlHandler(self.client_address,
                                                   self.headers, self.command,
                                                   self.path, self.rfile,
                                                   self.wfile)
            if self.command == "GET":
                return controler.do_GET()
            elif self.command == "POST":
                return controler.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(
                config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 12
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controler = web_control.ControlHandler(self.client_address, self.headers, self.command, self.path, self.rfile, self.wfile)
            if self.command == "GET":
                return controler.do_GET()
            elif self.command == "POST":
                return controler.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            #xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        if self.path == "http://www.twitter.com/xxnet":
            xlog.debug("%s %s", self.command, self.path)
            # for web_ui status page
            # auto detect browser proxy setting is work
            return self.wfile.write(self.self_check_response_data)

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            content_length = 'Content-Length: 0\r\n' if host.endswith('.google.com.hk') else ''
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\n%s\r\n' % (self.path.replace('http://', 'https://', 1), content_length)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 13
0
    def do_CONNECT(self):
        if self.path != "https://www.twitter.com/xxnet":
            touch_active()

        host, _, port = self.path.rpartition(':')

        if host in config.HOSTS_GAE:
            return self.do_CONNECT_AGENT()
        if host in config.HOSTS_DIRECT:
            return self.do_CONNECT_DIRECT()

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_CONNECT_AGENT()
        if host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.do_CONNECT_DIRECT()

        return self.do_CONNECT_AGENT()
Exemplo n.º 14
0
    def do_CONNECT(self):
        if self.path != "https://www.twitter.com/xxnet":
            touch_active()

        host, _, port = self.path.rpartition(':')

        if host in config.HOSTS_GAE:
            return self.do_CONNECT_AGENT()
        if host in config.HOSTS_DIRECT:
            return self.do_CONNECT_DIRECT()

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_CONNECT_AGENT()
        if host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.do_CONNECT_DIRECT()

        return self.do_CONNECT_AGENT()
Exemplo n.º 15
0
    def do_METHOD(self):
        touch_active()
        # record active time.
        # backgroud thread will stop keep connection pool if no request for long time.

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            return self.wfile.write(
                ('HTTP/1.1 301\r\nContent-Length: 0\r\n\r\n').encode())

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            #xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        if host_ip == config.get_listen_ip():
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        # redirect http request to https request
        # avoid key word filter when pass through GFW
        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(
                config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(
                ('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' %
                 self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 16
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get("Host", "")
        host_ip, _, port = host.rpartition(":")
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controler = web_control.ControlHandler(
                self.client_address, self.headers, self.command, self.path, self.rfile, self.wfile
            )
            if self.command == "GET":
                return controler.do_GET()
            elif self.command == "POST":
                return controler.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == "/" and host:
            self.path = "http://%s%s" % (host, self.path)
        elif not host and "://" in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(
                ("HTTP/1.1 301\r\nLocation: %s\r\n\r\n" % self.path.replace("http://", "https://", 1)).encode()
            )

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(
                ("HTTP/1.1 301\r\nLocation: %s\r\n\r\n" % self.path.replace("http://", "https://", 1)).encode()
            )

        return self.do_AGENT()
Exemplo n.º 17
0
    def do_METHOD(self):
        touch_active()

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            controler = web_control.ControlHandler(self.client_address, self.headers, self.command, self.path, self.rfile, self.wfile)
            if self.command == "GET":
                return controler.do_GET()
            elif self.command == "POST":
                return controler.do_POST()
            else:
                xlog.warn("method not defined: %s", self.command)
                return

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            #xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        if host_ip in socket.gethostbyname_ex(socket.gethostname())[-1]:
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()
Exemplo n.º 18
0
    def do_METHOD(self):
        touch_active()
        # record active time.
        # backgroud thread will stop keep connection pool if no request for long time.

        host = self.headers.get('Host', '')
        host_ip, _, port = host.rpartition(':')
        if host_ip == "127.0.0.1" and port == str(config.LISTEN_PORT):
            return self.wfile.write(('HTTP/1.1 301\r\nContent-Length: 0\r\n\r\n').encode())

        if self.path[0] == '/' and host:
            self.path = 'http://%s%s' % (host, self.path)
        elif not host and '://' in self.path:
            host = urlparse.urlparse(self.path).netloc

        if host.startswith("127.0.0.1") or host.startswith("localhost"):
            #xlog.warn("Your browser forward localhost to proxy.")
            return self.forward_local()

        if host_ip == config.get_listen_ip():
            xlog.info("Browse localhost by proxy")
            return self.forward_local()

        self.parsed_url = urlparse.urlparse(self.path)

        if host in config.HOSTS_GAE:
            return self.do_AGENT()

        # redirect http request to https request
        # avoid key word filter when pass through GFW
        if host in config.HOSTS_FWD or host in config.HOSTS_DIRECT:
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        if host.endswith(config.HOSTS_GAE_ENDSWITH):
            return self.do_AGENT()

        if host.endswith(config.HOSTS_FWD_ENDSWITH) or host.endswith(config.HOSTS_DIRECT_ENDSWITH):
            return self.wfile.write(('HTTP/1.1 301\r\nLocation: %s\r\nContent-Length: 0\r\n\r\n' % self.path.replace('http://', 'https://', 1)).encode())

        return self.do_AGENT()