add http3 reverse proxy

This commit is contained in:
ginuerzh
2022-11-12 17:14:11 +08:00
parent f87183b652
commit c1b2d3b086
13 changed files with 542 additions and 102 deletions

View File

@ -6,19 +6,6 @@ import (
"net/http"
)
type readWriter struct {
r io.Reader
w io.Writer
}
func (rw *readWriter) Read(p []byte) (n int, err error) {
return rw.r.Read(p)
}
func (rw *readWriter) Write(p []byte) (n int, err error) {
return rw.w.Write(p)
}
type flushWriter struct {
w io.Writer
}

View File

@ -22,6 +22,7 @@ import (
"github.com/go-gost/core/handler"
"github.com/go-gost/core/logger"
md "github.com/go-gost/core/metadata"
xio "github.com/go-gost/x/internal/io"
netpkg "github.com/go-gost/x/internal/net"
sx "github.com/go-gost/x/internal/util/selector"
"github.com/go-gost/x/registry"
@ -200,7 +201,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
start := time.Now()
log.Debugf("%s <-> %s", req.RemoteAddr, addr)
netpkg.Transport(&readWriter{r: req.Body, w: flushWriter{w}}, cc)
netpkg.Transport(xio.NewReadWriter(req.Body, flushWriter{w}), cc)
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Debugf("%s >-< %s", req.RemoteAddr, addr)