TimeoutHandler returns a Handler that runs h with the given time limit.
The new Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with a 503 Service Unavailable error and the given message in its body. (If msg is empty, a suitable default message will be sent.) After such a timeout, writes by h to its ResponseWriter will return ErrHandlerTimeout.
TimeoutHandler buffers all Handler writes to memory and does not support the Hijacker or Flusher interfaces.
}) ts := httptest.NewServer(TimeoutHandler(delayHi, 20*time.Millisecond, "")) defer ts.Close()
}) ts := httptest.NewServer(TimeoutHandler(delay204, time.Nanosecond, "")) defer ts.Close()
} timeout := 300 * time.Millisecond ts := httptest.NewServer(TimeoutHandler(handler, timeout, "")) defer ts.Close() // Issue was caused by the timeout handler starting the timer when
TimeoutHandler is referenced in 49 repositoriesgithub.com/golang/go
- 4 references in src/net/http/serve_test.go
- 4 references in libgo/go/net/http/serve_test.go