mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
Add support for passing headers to remote server
Add a new passRequestHeaders field to Proxy that identifies headers to pass from inbound request to remote servers. Also add associated flag to imageproxy CLI. This is initially added to support remote servers that require an authorization token. Fixes #321
This commit is contained in:
parent
006b99f6a2
commit
d94e5610d6
2 changed files with 11 additions and 0 deletions
|
@ -39,6 +39,7 @@ var referrers = flag.String("referrers", "", "comma separated list of allowed re
|
|||
var includeReferer = flag.Bool("includeReferer", false, "include referer header in remote requests")
|
||||
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 cache tieredCache
|
||||
var signatureKeys signatureKeyList
|
||||
var scaleUp = flag.Bool("scaleUp", false, "allow images to scale beyond their original dimensions")
|
||||
|
@ -70,6 +71,9 @@ func main() {
|
|||
if *contentTypes != "" {
|
||||
p.ContentTypes = strings.Split(*contentTypes, ",")
|
||||
}
|
||||
if *passRequestHeaders != "" {
|
||||
p.PassRequestHeaders = strings.Split(*passRequestHeaders, ",")
|
||||
}
|
||||
p.SignatureKeys = signatureKeys
|
||||
if *baseURL != "" {
|
||||
var err error
|
||||
|
|
|
@ -85,6 +85,10 @@ type Proxy struct {
|
|||
|
||||
// The User-Agent used by imageproxy when requesting origin image
|
||||
UserAgent string
|
||||
|
||||
// PassRequestHeaders identifies HTTP headers to pass from inbound
|
||||
// requests to the proxied server.
|
||||
PassRequestHeaders []string
|
||||
}
|
||||
|
||||
// NewProxy constructs a new proxy. The provided http RoundTripper will be
|
||||
|
@ -179,6 +183,9 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
|||
// pass along the referer header from the original request
|
||||
copyHeader(actualReq.Header, r.Header, "referer")
|
||||
}
|
||||
if len(p.PassRequestHeaders) != 0 {
|
||||
copyHeader(actualReq.Header, r.Header, p.PassRequestHeaders...)
|
||||
}
|
||||
if p.FollowRedirects {
|
||||
// FollowRedirects is true (default), ensure that the redirected host is allowed
|
||||
p.Client.CheckRedirect = func(newreq *http.Request, via []*http.Request) error {
|
||||
|
|
Loading…
Reference in a new issue