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:
parent
a27bf242c0
commit
6aca1e0b20
1 changed files with 5 additions and 1 deletions
|
@ -159,7 +159,11 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
||||||
if p.UserAgent != "" {
|
if p.UserAgent != "" {
|
||||||
actualReq.Header.Set("User-Agent", 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)
|
resp, err := p.Client.Do(actualReq)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("error fetching remote image: %v", err)
|
msg := fmt.Sprintf("error fetching remote image: %v", err)
|
||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
|
@ -170,7 +174,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
cached := resp.Header.Get(httpcache.XFromCache)
|
cached := resp.Header.Get(httpcache.XFromCache)
|
||||||
if p.Verbose {
|
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")
|
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")
|
||||||
|
|
Loading…
Reference in a new issue