mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
minor cleanup of error messages
- used same string for logging and error response to ensure they stay in sync - pass through any http error status codes from remote URLs
This commit is contained in:
parent
8ada90ffd2
commit
2dd79ebd20
2 changed files with 13 additions and 8 deletions
2
data.go
2
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue