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