Skip to content

Commit 6aca1e0

Browse files
committed
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
1 parent a27bf24 commit 6aca1e0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

imageproxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
159159
if p.UserAgent != "" {
160160
actualReq.Header.Set("User-Agent", p.UserAgent)
161161
}
162+
if len(p.ContentTypes) != 0 {
163+
actualReq.Header.Set("Accept", strings.Join(p.ContentTypes, ", "))
164+
}
162165
resp, err := p.Client.Do(actualReq)
166+
163167
if err != nil {
164168
msg := fmt.Sprintf("error fetching remote image: %v", err)
165169
log.Print(msg)
@@ -170,7 +174,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
170174

171175
cached := resp.Header.Get(httpcache.XFromCache)
172176
if p.Verbose {
173-
log.Printf("request: %v (served from cache: %v)", *req, cached == "1")
177+
log.Printf("request: %+v (served from cache: %t)", *actualReq, cached == "1")
174178
}
175179

176180
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")

0 commit comments

Comments
 (0)