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()
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()
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()
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()