mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
proxy non-200 responses with original status code
Some sites return a 404 image, and most browsers render them properly. We should pass them along as well. see also: atmos/camo#75 and atmos/camo#77
This commit is contained in:
parent
bdf995c94f
commit
396afb8a87
1 changed files with 1 additions and 7 deletions
|
@ -113,13 +113,6 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
cached := resp.Header.Get(httpcache.XFromCache)
|
cached := resp.Header.Get(httpcache.XFromCache)
|
||||||
glog.Infof("request: %v (served from cache: %v)", *req, cached == "1")
|
glog.Infof("request: %v (served from cache: %v)", *req, cached == "1")
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
msg := fmt.Sprintf("remote URL %q returned status: %v", req.URL, resp.Status)
|
|
||||||
glog.Error(msg)
|
|
||||||
http.Error(w, msg, resp.StatusCode)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
copyHeader(w, resp, "Last-Modified")
|
copyHeader(w, resp, "Last-Modified")
|
||||||
copyHeader(w, resp, "Expires")
|
copyHeader(w, resp, "Expires")
|
||||||
copyHeader(w, resp, "Etag")
|
copyHeader(w, resp, "Etag")
|
||||||
|
@ -131,6 +124,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
copyHeader(w, resp, "Content-Length")
|
copyHeader(w, resp, "Content-Length")
|
||||||
copyHeader(w, resp, "Content-Type")
|
copyHeader(w, resp, "Content-Type")
|
||||||
|
w.WriteHeader(resp.StatusCode)
|
||||||
io.Copy(w, resp.Body)
|
io.Copy(w, resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue