From fcb54bd5765c5fb419267746e5a3e8df14f298c7 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Mon, 16 Dec 2024 20:48:11 +0800 Subject: [PATCH] fix observer for http2 --- handler/http2/handler.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/handler/http2/handler.go b/handler/http2/handler.go index 985bcf80..d1e28b86 100644 --- a/handler/http2/handler.go +++ b/handler/http2/handler.go @@ -109,6 +109,7 @@ func (h *http2Handler) Handle(ctx context.Context, conn net.Conn, opts ...handle "remote": conn.RemoteAddr().String(), "local": conn.LocalAddr().String(), "sid": ctxvalue.SidFromContext(ctx), + "client": ro.ClientIP, }) log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr()) defer func() { @@ -262,6 +263,8 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req fw.Flush() } + rw := xio.NewReadWriter(req.Body, flushWriter{w}) + // compatible with HTTP1.x if hj, ok := w.(http.Hijacker); ok && req.ProtoMajor == 1 { // we take over the underly connection @@ -274,19 +277,12 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req } defer conn.Close() - start := time.Now() - log.Infof("%s <-> %s", conn.RemoteAddr(), host) - xnet.Transport(conn, cc) - log.WithFields(map[string]any{ - "duration": time.Since(start), - }).Infof("%s >-< %s", conn.RemoteAddr(), host) - - return nil + rw = conn } - rw := traffic_wrapper.WrapReadWriter( + rw = traffic_wrapper.WrapReadWriter( h.limiter, - xio.NewReadWriter(req.Body, flushWriter{w}), + rw, clientID, limiter.ScopeOption(limiter.ScopeClient), limiter.ServiceOption(h.options.Service),