func (receiver *httpReceiver) handleHTTPS(rw http.ResponseWriter, req *http.Request) { hj := rw.(http.Hijacker) cli, _, err := hj.Hijack() if err != nil { logger.Errorf("http----->handle hijack error %s", err) return } hst := req.URL.Host domain, port := receiver.getHostAndPort("https", hst) if ip := net.ParseIP(domain); ip != nil { if config.ParserIP(domain) { cli.Write(httpOk) handleChina(cli, hst) return } receiver.handleTunnel(cli, domain, port, false) return } if config.ParserDomain(domain) && !config.IsInWhiteList(domain) { cli.Write(httpOk) handleChina(cli, hst) return } receiver.handleTunnel(cli, domain, port, true) }
func (receiver *httpReceiver) handleHTTP(rw http.ResponseWriter, req *http.Request) { clearProxyHeader(req) hst := req.URL.Host domain, port := receiver.getHostAndPort("http", hst) if ip := net.ParseIP(domain); ip != nil { if config.ParserIP(domain) { receiver.handleSimpleHTTP(rw, req) return } receiver.handleHTTPTunnel(rw, req, domain, port, false) return } if config.ParserDomain(domain) && !config.IsInWhiteList(domain) { receiver.handleSimpleHTTP(rw, req) return } receiver.handleHTTPTunnel(rw, req, domain, port, true) }
func (receiver *receiver) handleConnection(conn net.Conn) { var err error if err = receiver.handshake(conn); err != nil { logger.Errorf("Socks5--->handshake error %s\n", err) return } //set default timeout cfg.SetTimeout(conn.SetReadDeadline, receiver.config.Timeout) //conn.SetReadDeadline(time.Now().Add(time.Duration(s.config.Timeout) * time.Second)) rawAddr, host, domian, err := receiver.request(conn) if err != nil { logger.Errorf("Socks5--->get host failed %s\n", err) return } _, err = conn.Write([]byte{0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x43}) if err != nil { logger.Errorf("Socks5--->error send data to client %s\n", err) return } //need connect to remote server or not if domian && !cfg.IsInWhiteList(strings.Split(host, ":")[0]) { result := cfg.ParserDomain(strings.Split(host, ":")[0]) if result { handleChina(conn, host) return } } else if !domian { result := cfg.ParserIP(strings.Split(host, ":")[0]) if result { handleChina(conn, host) return } } ci, flag, err := client.NewRemoteServer(receiver.config).ChooseServer() if err != nil { logger.Errorf("Socks5--->connect to server failed %s", err) return } if flag { cli := ci.(*client.SSLClient) cfg.SetTimeout(cli.Conn.SetReadDeadline, receiver.config.Timeout) defer func() { cli.Conn.Close() conn.Close() }() if _, err = cli.Conn.Write(rawAddr); err != nil { logger.Errorf("Socks5--->handle error message when write data %s \n", err) return } pipe(&cli.Conn, conn) return } cli := ci.(*client.Client) cfg.SetTimeout(cli.Conn.SetReadDeadline, receiver.config.Timeout) //cli.Conn.SetReadDeadline(time.Now().Add(time.Duration(s.config.Timeout) * time.Second)) defer func() { cli.Conn.Close() conn.Close() }() if _, err = cli.Conn.Write(rawAddr); err != nil { logger.Errorf("Socks5--->handle error message when write data %s \n", err) return } pipe(cli.Conn, conn) }