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

return early if remote URL returns a 404

This commit is contained in:
Will Norris 2023-05-12 19:04:10 -07:00
parent 1ba0bd0a6d
commit a9b6594b41

View file

@ -221,6 +221,12 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
// close the original resp.Body, even if we wrap it in a NopCloser below
defer resp.Body.Close()
// return early on 404s. Perhaps handle additional status codes here?
if resp.StatusCode == http.StatusNotFound {
http.Error(w, "not found", http.StatusNotFound)
return
}
cached := resp.Header.Get(httpcache.XFromCache) == "1"
if p.Verbose {
p.logf("request: %+v (served from cache: %t)", *actualReq, cached)