Skip to content

Commit

Permalink
fix observer for http2
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed Dec 16, 2024
1 parent 5206d1b commit fcb54bd
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions handler/http2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit fcb54bd

Please sign in to comment.