0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-30 22:34:18 -05:00

add String method to Request

This commit is contained in:
Will Norris 2015-05-11 17:12:03 -07:00
parent fc093b71eb
commit b1de3a9dd6
2 changed files with 9 additions and 6 deletions

View file

@ -186,6 +186,14 @@ type Request struct {
Options Options // Image transformation to perform
}
// String returns the request URL as a string, with r.Options encoded in the
// URL fragment.
func (r Request) String() string {
u := *r.URL
u.Fragment = r.Options.String()
return u.String()
}
// NewRequest parses an http.Request into an imageproxy Request. Options and
// the remote image URL are specified in the request path, formatted as:
// /{options}/{remote_url}. Options may be omitted, so a request path may

View file

@ -95,12 +95,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
u := req.URL.String()
if req.Options != emptyOptions {
u += "#" + req.Options.String()
}
resp, err := p.Client.Get(u)
resp, err := p.Client.Get(req.String())
if err != nil {
msg := fmt.Sprintf("error fetching remote image: %v", err)
glog.Error(msg)