mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-13 22:12:40 +02:00
Modifications of image proxy
This commit is contained in:
parent
7eeacfca7a
commit
2913b086ac
1 changed files with 12 additions and 0 deletions
12
data.go
12
data.go
|
|
@ -336,6 +336,7 @@ func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
|
||||||
req := &Request{Original: r}
|
req := &Request{Original: r}
|
||||||
|
|
||||||
path := r.URL.EscapedPath()[1:] // strip leading slash
|
path := r.URL.EscapedPath()[1:] // strip leading slash
|
||||||
|
path, err = decodeUrl(path)
|
||||||
req.URL, err = parseURL(path)
|
req.URL, err = parseURL(path)
|
||||||
if err != nil || !req.URL.IsAbs() {
|
if err != nil || !req.URL.IsAbs() {
|
||||||
// first segment should be options
|
// first segment should be options
|
||||||
|
|
@ -378,3 +379,14 @@ func parseURL(s string) (*url.URL, error) {
|
||||||
s = reCleanedURL.ReplaceAllString(s, "$1://$2")
|
s = reCleanedURL.ReplaceAllString(s, "$1://$2")
|
||||||
return url.Parse(s)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue