Modifications of image proxy

This commit is contained in:
Matthew Beatty 2020-12-22 10:32:34 -05:00
parent 7eeacfca7a
commit 2913b086ac

12
data.go
View file

@ -336,6 +336,7 @@ func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
req := &Request{Original: r}
path := r.URL.EscapedPath()[1:] // strip leading slash
path, err = decodeUrl(path)
req.URL, err = parseURL(path)
if err != nil || !req.URL.IsAbs() {
// first segment should be options
@ -378,3 +379,14 @@ func parseURL(s string) (*url.URL, error) {
s = reCleanedURL.ReplaceAllString(s, "$1://$2")
return url.Parse(s)
}
var reIsEncodedUrl = regexp.MustCompile(`^https?%`)
func decodeUrl(s string) (string, error) {
var isUrlEncoded = reIsEncodedUrl.MatchString(s)
if isUrlEncoded {
return url.QueryUnescape(s)
} else {
return s, nil
}
}