http2: added non-connect request support

This commit is contained in:
ginuerzh
2025-07-30 10:06:52 +08:00
parent 208d18125c
commit 3bbc10796c
+10 -3
View File
@@ -323,9 +323,15 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
return nil return nil
} }
// TODO: forward request start := time.Now()
resp.StatusCode = http.StatusBadRequest log.Infof("%s <-> %s", req.RemoteAddr, host)
w.WriteHeader(resp.StatusCode) if err := h.forwardRequest(w, req, cc); err != nil {
log.Info("%s - %s: %s", req.RemoteAddr, host, err)
}
log.WithFields(map[string]any{
"duration": time.Since(start),
}).Infof("%s >-< %s", req.RemoteAddr, host)
return nil return nil
} }
@@ -456,6 +462,7 @@ func (h *http2Handler) authenticate(ctx context.Context, w http.ResponseWriter,
return return
} }
func (h *http2Handler) forwardRequest(w http.ResponseWriter, r *http.Request, rw io.ReadWriter) (err error) { func (h *http2Handler) forwardRequest(w http.ResponseWriter, r *http.Request, rw io.ReadWriter) (err error) {
if err = r.Write(rw); err != nil { if err = r.Write(rw); err != nil {
return return