0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

set Accept header on requests if contentTypes set

If the imageproxy instance is configured to only accept certain content
types (which defaults to "image/*"), set that as the accept header on
outbound requests.

Also log more information about the outbound request when the `Verbose`
option is set, so the request headers can be seen in the logs.

Fixes #165
Refs #132
This commit is contained in:
Will Norris 2019-03-24 18:11:12 +00:00
parent a27bf242c0
commit 6aca1e0b20

View file

@ -159,7 +159,11 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
if p.UserAgent != "" {
actualReq.Header.Set("User-Agent", p.UserAgent)
}
if len(p.ContentTypes) != 0 {
actualReq.Header.Set("Accept", strings.Join(p.ContentTypes, ", "))
}
resp, err := p.Client.Do(actualReq)
if err != nil {
msg := fmt.Sprintf("error fetching remote image: %v", err)
log.Print(msg)
@ -170,7 +174,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
cached := resp.Header.Get(httpcache.XFromCache)
if p.Verbose {
log.Printf("request: %v (served from cache: %v)", *req, cached == "1")
log.Printf("request: %+v (served from cache: %t)", *actualReq, cached == "1")
}
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")