From b1de3a9dd6071f709379c26e12863f8b127d31e9 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 11 May 2015 17:12:03 -0700 Subject: [PATCH] add String method to Request --- data.go | 8 ++++++++ imageproxy.go | 7 +------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/data.go b/data.go index 6a19004..6cfda2a 100644 --- a/data.go +++ b/data.go @@ -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 diff --git a/imageproxy.go b/imageproxy.go index 9993098..fdab7f6 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -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)