From a9b6594b411ab1e6f221feb65daebaf4ec5ca3f9 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 12 May 2023 19:04:10 -0700 Subject: [PATCH] return early if remote URL returns a 404 --- imageproxy.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imageproxy.go b/imageproxy.go index ce671db..699ff0c 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -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)