fix observer for http2

This commit is contained in:
ginuerzh
2024-12-16 20:48:11 +08:00
parent 5206d1bd58
commit fcb54bd576
+6 -10
View File
@@ -109,6 +109,7 @@ func (h *http2Handler) Handle(ctx context.Context, conn net.Conn, opts ...handle
"remote": conn.RemoteAddr().String(), "remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(), "local": conn.LocalAddr().String(),
"sid": ctxvalue.SidFromContext(ctx), "sid": ctxvalue.SidFromContext(ctx),
"client": ro.ClientIP,
}) })
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr()) log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() { defer func() {
@@ -262,6 +263,8 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
fw.Flush() fw.Flush()
} }
rw := xio.NewReadWriter(req.Body, flushWriter{w})
// compatible with HTTP1.x // compatible with HTTP1.x
if hj, ok := w.(http.Hijacker); ok && req.ProtoMajor == 1 { if hj, ok := w.(http.Hijacker); ok && req.ProtoMajor == 1 {
// we take over the underly connection // we take over the underly connection
@@ -274,19 +277,12 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
} }
defer conn.Close() defer conn.Close()
start := time.Now() rw = conn
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 := traffic_wrapper.WrapReadWriter( rw = traffic_wrapper.WrapReadWriter(
h.limiter, h.limiter,
xio.NewReadWriter(req.Body, flushWriter{w}), rw,
clientID, clientID,
limiter.ScopeOption(limiter.ScopeClient), limiter.ScopeOption(limiter.ScopeClient),
limiter.ServiceOption(h.options.Service), limiter.ServiceOption(h.options.Service),