diff --git a/data.go b/data.go index d390cd3..eee30c7 100644 --- a/data.go +++ b/data.go @@ -154,7 +154,7 @@ func NewRequest(r *http.Request) (*Request, error) { } if req.URL.Scheme != "http" && req.URL.Scheme != "https" { - return nil, URLError{"remote URL must have http or https URL", r.URL} + return nil, URLError{"remote URL must have http or https scheme", r.URL} } // query string is always part of the remote URL diff --git a/imageproxy.go b/imageproxy.go index 3431aef..4761ed4 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -66,14 +66,16 @@ func NewProxy(transport http.RoundTripper, cache Cache) *Proxy { func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { req, err := NewRequest(r) if err != nil { - glog.Errorf("invalid request URL: %v", err) - http.Error(w, fmt.Sprintf("invalid request URL: %v", err), http.StatusBadRequest) + msg := fmt.Sprintf("invalid request URL: %v", err) + glog.Error(msg) + http.Error(w, msg, http.StatusBadRequest) return } if !p.allowed(req.URL) { - glog.Errorf("remote URL is not for an allowed host: %v", req.URL) - http.Error(w, fmt.Sprintf("remote URL is not for an allowed host: %v", req.URL), http.StatusBadRequest) + msg := fmt.Sprintf("remote URL is not for an allowed host: %v", req.URL) + glog.Error(msg) + http.Error(w, msg, http.StatusBadRequest) return } @@ -83,13 +85,16 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { } resp, err := p.Client.Get(u) if err != nil { - glog.Errorf("error fetching remote image: %v", err) - http.Error(w, fmt.Sprintf("Error fetching remote image: %v", err), http.StatusInternalServerError) + msg := fmt.Sprintf("error fetching remote image: %v", err) + glog.Error(msg) + http.Error(w, msg, http.StatusInternalServerError) return } if resp.StatusCode != http.StatusOK { - http.Error(w, fmt.Sprintf("Remote URL %q returned status: %v", req.URL, resp.Status), http.StatusInternalServerError) + msg := fmt.Sprintf("remote URL %q returned status: %v", req.URL, resp.Status) + glog.Error(msg) + http.Error(w, msg, resp.StatusCode) return }