mirror of
https://github.com/willnorris/imageproxy.git
synced 2025-01-06 22:40:34 -05:00
log requests and whether response is from cache
also make sure request body is always closed fixes #17
This commit is contained in:
parent
1bf0515cef
commit
2b84ef01ed
1 changed files with 5 additions and 1 deletions
|
@ -94,6 +94,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if req.Options != emptyOptions {
|
if req.Options != emptyOptions {
|
||||||
u += "#" + req.Options.String()
|
u += "#" + req.Options.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := p.Client.Get(u)
|
resp, err := p.Client.Get(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("error fetching remote image: %v", err)
|
msg := fmt.Sprintf("error fetching remote image: %v", err)
|
||||||
|
@ -101,6 +102,10 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, msg, http.StatusInternalServerError)
|
http.Error(w, msg, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
cached := resp.Header.Get(httpcache.XFromCache)
|
||||||
|
glog.Infof("request: %v (served from cache: %v)", *req, cached == "1")
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
msg := fmt.Sprintf("remote URL %q returned status: %v", req.URL, resp.Status)
|
msg := fmt.Sprintf("remote URL %q returned status: %v", req.URL, resp.Status)
|
||||||
|
@ -120,7 +125,6 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
copyHeader(w, resp, "Content-Length")
|
copyHeader(w, resp, "Content-Length")
|
||||||
copyHeader(w, resp, "Content-Type")
|
copyHeader(w, resp, "Content-Type")
|
||||||
defer resp.Body.Close()
|
|
||||||
io.Copy(w, resp.Body)
|
io.Copy(w, resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue