MCPcopy Index your code
hub / github.com/chain/Core / timeoutContextHandler

Function timeoutContextHandler

core/api.go:288–301  ·  view source on GitHub ↗

timeoutContextHandler propagates the timeout, if any, provided as a header in the http request.

(handler http.Handler)

Source from the content-addressed store, hash-verified

286// timeoutContextHandler propagates the timeout, if any, provided as a header
287// in the http request.
288func 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.

Callers 1

buildHandlerMethod · 0.85

Calls 2

GetMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected