diff --git a/imageproxy.go b/imageproxy.go index 22a7c56..4afc67f 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -32,6 +32,7 @@ import ( "github.com/golang/glog" "github.com/gregjones/httpcache" + tphttp "willnorris.com/go/imageproxy/third_party/http" ) // Proxy serves image requests. @@ -105,7 +106,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { var h http.Handler = http.HandlerFunc(p.serveImage) if p.Timeout > 0 { - h = http.TimeoutHandler(h, p.Timeout, "") + h = tphttp.TimeoutHandler(h, p.Timeout, "Gateway timeout waiting for remote resource.") } h.ServeHTTP(w, r) } diff --git a/third_party/http/server.go b/third_party/http/server.go index 133c3c9..b17943b 100644 --- a/third_party/http/server.go +++ b/third_party/http/server.go @@ -18,7 +18,7 @@ import ( // // 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. +// a 504 Gateway Timeout 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. @@ -89,7 +89,7 @@ func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { case <-timeout: tw.mu.Lock() defer tw.mu.Unlock() - w.WriteHeader(http.StatusServiceUnavailable) + w.WriteHeader(http.StatusGatewayTimeout) io.WriteString(w, h.errorBody()) tw.timedOut = true return