timeoutContextHandler propagates the timeout, if any, provided as a header in the http request.
(handler http.Handler)
| 286 | // timeoutContextHandler propagates the timeout, if any, provided as a header |
| 287 | // in the http request. |
| 288 | func timeoutContextHandler(handler http.Handler) http.Handler { |
| 289 | return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| 290 | timeout, err := time.ParseDuration(req.Header.Get(rpc.HeaderTimeout)) |
| 291 | if err != nil { |
| 292 | handler.ServeHTTP(w, req) // unmodified |
| 293 | return |
| 294 | } |
| 295 | |
| 296 | ctx := req.Context() |
| 297 | ctx, cancel := context.WithTimeout(ctx, timeout) |
| 298 | defer cancel() |
| 299 | handler.ServeHTTP(w, req.WithContext(ctx)) |
| 300 | }) |
| 301 | } |
| 302 | |
| 303 | // blockchainIDHandler adds the Blockchain-ID HTTP header to all |
| 304 | // requests. |
no test coverage detected