@@ -222,10 +222,6 @@ func (r Request) String() string {
222222 return u .String ()
223223}
224224
225- // reCleanedURL matches an absolute HTTP URL that has been munged by path.Clean
226- // or a webserver that collapses multiple slashes.
227- var reCleanedURL = regexp .MustCompile (`^(https?):/([^/])` )
228-
229225// NewRequest parses an http.Request into an imageproxy Request. Options and
230226// the remote image URL are specified in the request path, formatted as:
231227// /{options}/{remote_url}. Options may be omitted, so a request path may
@@ -244,8 +240,7 @@ func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
244240 req := & Request {Original : r }
245241
246242 path := r .URL .Path [1 :] // strip leading slash
247- path = reCleanedURL .ReplaceAllString (path , "$1://$2" )
248- req .URL , err = url .Parse (path )
243+ req .URL , err = parseURL (path )
249244 if err != nil || ! req .URL .IsAbs () {
250245 // first segment should be options
251246 parts := strings .SplitN (path , "/" , 2 )
@@ -254,7 +249,7 @@ func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
254249 }
255250
256251 var err error
257- req .URL , err = url . Parse (parts [1 ])
252+ req .URL , err = parseURL (parts [1 ])
258253 if err != nil {
259254 return nil , URLError {fmt .Sprintf ("unable to parse remote URL: %v" , err ), r .URL }
260255 }
@@ -278,3 +273,12 @@ func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
278273 req .URL .RawQuery = r .URL .RawQuery
279274 return req , nil
280275}
276+
277+ var reCleanedURL = regexp .MustCompile (`^(https?):/+([^/])` )
278+
279+ // parseURL parses s as a URL, handling URLs that have been munged by
280+ // path.Clean or a webserver that collapses multiple slashes.
281+ func parseURL (s string ) (* url.URL , error ) {
282+ s = reCleanedURL .ReplaceAllString (s , "$1://$2" )
283+ return url .Parse (s )
284+ }
0 commit comments