0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

return 504 status for timeout errors

modify custom TimeoutHandler to return 504 error and switch imageproxy
to use that func.

Fixes #75
This commit is contained in:
Will Norris 2016-11-29 15:39:59 -08:00
parent e180185856
commit 576b7c023a
2 changed files with 4 additions and 3 deletions

View file

@ -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)
}

View file

@ -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