Skip to content

Commit 867a46b

Browse files
committed
provide better debug info
1 parent 77b426e commit 867a46b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

modules/web/handler.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,22 @@ func hasResponseBeenWritten(argsIn []reflect.Value) bool {
130130
// toHandlerProvider converts a handler to a handler provider
131131
// A handler provider is a function that takes a "next" http.Handler, it can be used as a middleware
132132
func toHandlerProvider(handler any) func(next http.Handler) http.Handler {
133-
if hp, ok := handler.(func(next http.Handler) http.Handler); ok {
134-
return hp
135-
}
136-
137133
funcInfo := routing.GetFuncInfo(handler)
138134
fn := reflect.ValueOf(handler)
139135
if fn.Type().Kind() != reflect.Func {
140136
panic(fmt.Sprintf("handler must be a function, but got %s", fn.Type()))
141137
}
142138

139+
if hp, ok := handler.(func(next http.Handler) http.Handler); ok {
140+
return func(next http.Handler) http.Handler {
141+
h := hp(next) // this handle could be dynamically generated, so we can't use it for debug info
142+
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
143+
routing.UpdateFuncInfo(req.Context(), funcInfo)
144+
h.ServeHTTP(resp, req)
145+
})
146+
}
147+
}
148+
143149
provider := func(next http.Handler) http.Handler {
144150
return http.HandlerFunc(func(respOrig http.ResponseWriter, req *http.Request) {
145151
// wrap the response writer to check whether the response has been written

0 commit comments

Comments
 (0)