diff --git a/easyss.go b/easyss.go index de5d6385..6b84cdc2 100644 --- a/easyss.go +++ b/easyss.go @@ -614,6 +614,7 @@ func (ss *Easyss) initHTTPOutboundClient() error { }) } + client.SetProxy(nil) ss.httpOutboundClient = client return nil } diff --git a/httptunnel/local_conn.go b/httptunnel/local_conn.go index e7db319e..a2b93f86 100644 --- a/httptunnel/local_conn.go +++ b/httptunnel/local_conn.go @@ -144,27 +144,39 @@ func (l *LocalConn) pull() error { } func (l *LocalConn) push() error { - resp, err := l.client.R(). + r := l.client.R(). SetHeader("Content-Type", "application/json"). SetHeader("Transfer-Encoding", "chunked"). SetHeader("Accept-Encoding", "gzip"). SetHeader("Content-Encoding", "gzip"). - SetQueryParam(RequestIDQuery, l.uuid). - SetBody(l). - Post(l.serverAddr + "/push") - if err != nil { - return err - } + SetQueryParam(RequestIDQuery, l.uuid) - body, err := resp.ToBytes() - if err != nil { - return err - } - if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { - return fmt.Errorf("status code:%v, body:%v", resp.StatusCode, string(body)) - } + buf := bytespool.Get(cipherstream.MaxPayloadSize) + defer bytespool.MustPut(buf) - return nil + for { + var resp *req.Response + n, err1 := l.Read(buf) + if n > 0 { + var err2 error + resp, err2 = r.SetBody(buf[:n]).Post(l.serverAddr + "/push") + if err2 != nil { + return errors.Join(err1, err2) + } + } + if resp != nil { + body, err3 := resp.ToBytes() + if err3 != nil { + return err3 + } + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { + return fmt.Errorf("status code:%v, body:%v", resp.StatusCode, string(body)) + } + } + if err1 != nil { + return err1 + } + } } // Read implements io.Reader diff --git a/httptunnel/server.go b/httptunnel/server.go index 37671cf7..c5921245 100644 --- a/httptunnel/server.go +++ b/httptunnel/server.go @@ -236,8 +236,9 @@ func (s *Server) push(w http.ResponseWriter, r *http.Request) { break } } - if err != nil { + if err != nil && !errors.Is(err, io.EOF) { _ = conns[0].Close() + return } writeSuccess(w) diff --git a/local.go b/local.go index d7dd27fa..46711019 100644 --- a/local.go +++ b/local.go @@ -137,7 +137,7 @@ func (ss *Easyss) validateAddr(addr string) error { serverPort := strconv.FormatInt(int64(ss.ServerPort()), 10) if !util.IsIP(host) { if host == ss.Server() && port == serverPort { - return fmt.Errorf("target host,port equals to server host,port, which may caused infinite-loop") + return fmt.Errorf("target %s:%s equals to server host,port, which may caused infinite-loop", host, port) } return nil } @@ -149,7 +149,7 @@ func (ss *Easyss) validateAddr(addr string) error { return fmt.Errorf("target %s is ipv6, but ipv6 network is disabled", host) } if (host == ss.ServerIP() || host == ss.ServerIPV6()) && port == serverPort { - return fmt.Errorf("target host:%v equals server host ip, which may caused infinite-loop", host) + return fmt.Errorf("target %s:%s equals server host,port, which may caused infinite-loop", host, port) } return nil