mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -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 {
|
||||
u += "#" + req.Options.String()
|
||||
}
|
||||
|
||||
resp, err := p.Client.Get(u)
|
||||
if err != nil {
|
||||
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)
|
||||
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 {
|
||||
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-Type")
|
||||
defer resp.Body.Close()
|
||||
io.Copy(w, resp.Body)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue