|
|
|
@ -181,12 +181,17 @@ func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) { |
|
|
|
|
func (s *Server) filter() mux.MiddlewareFunc { |
|
|
|
|
return func(next http.Handler) http.Handler { |
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
|
|
|
|
ctx, cancel := context.WithCancel(req.Context()) |
|
|
|
|
defer cancel() |
|
|
|
|
var ( |
|
|
|
|
ctx context.Context |
|
|
|
|
cancel context.CancelFunc |
|
|
|
|
) |
|
|
|
|
if s.timeout > 0 { |
|
|
|
|
ctx, cancel = context.WithTimeout(ctx, s.timeout) |
|
|
|
|
defer cancel() |
|
|
|
|
ctx, cancel = context.WithTimeout(req.Context(), s.timeout) |
|
|
|
|
} else { |
|
|
|
|
ctx, cancel = context.WithCancel(req.Context()) |
|
|
|
|
} |
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
pathTemplate := req.URL.Path |
|
|
|
|
if route := mux.CurrentRoute(req); route != nil { |
|
|
|
|
// /path/123 -> /path/{id}
|
|
|
|
|