From 2913b086acb76ac5c9895e5f1fd2923bfd8ba232 Mon Sep 17 00:00:00 2001 From: Matthew Beatty Date: Tue, 22 Dec 2020 10:32:34 -0500 Subject: [PATCH] Modifications of image proxy --- data.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/data.go b/data.go index 424f4ac..7872572 100644 --- a/data.go +++ b/data.go @@ -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 + } +} \ No newline at end of file