mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-04-25 04:46:24 +02:00
allow customizing response headers passed to client
A nil slice of headers will use the previous set of default response headers to maintain existing behavior. The same list of headers is repeated as the default flag value in `cmd/imageproxy` as documentation for users to know what values they are overriding (and might want to still include). Fixes #387
This commit is contained in:
parent
554bfc5d8e
commit
7f3639886b
2 changed files with 17 additions and 1 deletions
|
|
@ -94,6 +94,10 @@ type Proxy struct {
|
|||
// requests to the proxied server.
|
||||
PassRequestHeaders []string
|
||||
|
||||
// PassResponseHeaders identifies HTTP headers to pass from server responses to the proxy client.
|
||||
// If nil, a default set of headers is passed: Cache-Control, Last-Modified, Expires, Etag, Link.
|
||||
PassResponseHeaders []string
|
||||
|
||||
// MinimumCacheDuration is the minimum duration to cache remote images.
|
||||
// This will override cache duration from the remote server.
|
||||
MinimumCacheDuration time.Duration
|
||||
|
|
@ -312,7 +316,12 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
|||
metricServedFromCache.Inc()
|
||||
}
|
||||
|
||||
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")
|
||||
if p.PassResponseHeaders == nil {
|
||||
// pass default set of response headers
|
||||
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")
|
||||
} else {
|
||||
copyHeader(w.Header(), resp.Header, p.PassResponseHeaders...)
|
||||
}
|
||||
|
||||
if should304(r, resp) {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue