mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
be a little more precise in copying headers
it doesn't matter too much right now, given the headers that are being copied, but this now makes sure that all header values get copied over if multiple are present.
This commit is contained in:
parent
bf8d7a0cd8
commit
1bf0515cef
1 changed files with 12 additions and 5 deletions
|
@ -109,21 +109,28 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Last-Modified", resp.Header.Get("Last-Modified"))
|
||||
w.Header().Add("Expires", resp.Header.Get("Expires"))
|
||||
w.Header().Add("Etag", resp.Header.Get("Etag"))
|
||||
copyHeader(w, resp, "Last-Modified")
|
||||
copyHeader(w, resp, "Expires")
|
||||
copyHeader(w, resp, "Etag")
|
||||
|
||||
if is304 := check304(r, resp); is304 {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Length", resp.Header.Get("Content-Length"))
|
||||
w.Header().Add("Content-Type", resp.Header.Get("Content-Type"))
|
||||
copyHeader(w, resp, "Content-Length")
|
||||
copyHeader(w, resp, "Content-Type")
|
||||
defer resp.Body.Close()
|
||||
io.Copy(w, resp.Body)
|
||||
}
|
||||
|
||||
func copyHeader(w http.ResponseWriter, r *http.Response, header string) {
|
||||
key := http.CanonicalHeaderKey(header)
|
||||
if value, ok := r.Header[key]; ok {
|
||||
w.Header()[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
// allowed returns whether the specified URL is on the whitelist of remote hosts.
|
||||
func (p *Proxy) allowed(u *url.URL) bool {
|
||||
if len(p.Whitelist) == 0 {
|
||||
|
|
Loading…
Reference in a new issue