mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-04-24 20:36: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
|
|
@ -39,6 +39,7 @@ var includeReferer = flag.Bool("includeReferer", false, "include referer header
|
|||
var followRedirects = flag.Bool("followRedirects", true, "follow redirects")
|
||||
var baseURL = flag.String("baseURL", "", "default base URL for relative remote URLs")
|
||||
var passRequestHeaders = flag.String("passRequestHeaders", "", "comma separatetd list of request headers to pass to remote server")
|
||||
var passResponseHeaders = flag.String("passResponseHeaders", "Cache-Control,Last-Modified,Expires,Etag,Link", "comma separated list of response headers to pass from remote server")
|
||||
var cache tieredCache
|
||||
var signatureKeys signatureKeyList
|
||||
var scaleUp = flag.Bool("scaleUp", false, "allow images to scale beyond their original dimensions")
|
||||
|
|
@ -75,6 +76,12 @@ func main() {
|
|||
if *passRequestHeaders != "" {
|
||||
p.PassRequestHeaders = strings.Split(*passRequestHeaders, ",")
|
||||
}
|
||||
if *passResponseHeaders != "" {
|
||||
p.PassResponseHeaders = strings.Split(*passResponseHeaders, ",")
|
||||
} else {
|
||||
// set to a non-nil empty slice to pass no headers.
|
||||
p.PassResponseHeaders = []string{}
|
||||
}
|
||||
p.SignatureKeys = signatureKeys
|
||||
if *baseURL != "" {
|
||||
var err error
|
||||
|
|
|
|||
|
|
@ -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