def http_handler(self): req_data = self.conn.recv(65537, socket.MSG_PEEK) if "\r\n" not in req_data: xlog.warn("http req:%s", req_data) return rp = req_data.split("\r\n") req_line = rp[0] words = req_line.split() if len(words) == 3: method, url, http_version = words elif len(words) == 2: method, url = words http_version = "HTTP/1.1" else: xlog.warn("http req line fail:%s", req_line) return if url.lower().startswith("http://"): o = urlparse.urlparse(url) host, port = netloc_to_host_port(o.netloc) p = url[7:].find("/") if p >= 0: path = url[7+p:] else: path = "/" else: # not proxy request, should be PAC xlog.debug("PAC %s %s from:%s", method, url, self.client_address) handler = pac_server.PacHandler(self.conn, self.client_address, None, xlog) return handler.handle() # xlog.debug("http %r connect to %s:%d", self.client_address, host, port) l = self.conn.recv(len(req_line)) if len(l) != len(req_line): xlog.error("req:%s l:%d", req_line, len(l)) return new_req_line = "%s %s %s" % (method, path, http_version) handle_domain_proxy(self.conn, host, port, self.client_address, new_req_line)
def http_handler(self): req_data = self.conn.recv(65537, socket.MSG_PEEK) rp = req_data.split("\r\n") req_line = rp[0] words = req_line.split() if len(words) == 3: method, url, http_version = words elif len(words) == 2: method, url = words http_version = "HTTP/1.1" else: xlog.warn("http req line fail:%s", req_line) return if url.lower().startswith("http://"): o = urlparse.urlparse(url) host, port = netloc_to_host_port(o.netloc) url_prex_len = url[7:].find("/") if url_prex_len >= 0: url_prex_len += 7 path = url[url_prex_len:] else: url_prex_len = len(url) path = "/" else: # not proxy request, should be PAC xlog.debug("PAC %s %s from:%s", method, url, self.client_address) handler = pac_server.PacHandler(self.conn, self.client_address, None, xlog) return handler.handle() #req_d = self.conn.recv(len(req_line)) #req_d = req_d.replace(url, path) sock = SocketWrap(self.conn, self.client_address[0], self.client_address[1]) sock.replace_pattern = [url[:url_prex_len], ""] xlog.debug("http %r connect to %s:%d %s %s", self.client_address, host, port, method, path) handle_domain_proxy(sock, host, port, self.client_address)