mirror of
https://github.com/Luzifer/preserve.git
synced 2024-12-20 17:51:18 +00:00
Fix: decode b64 URIs before generating cache path
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
4206f2719d
commit
262d5798c9
1 changed files with 9 additions and 9 deletions
18
main.go
18
main.go
|
@ -91,15 +91,6 @@ func handleCacheOnce(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCache(w http.ResponseWriter, r *http.Request, uri string, update bool) {
|
func handleCache(w http.ResponseWriter, r *http.Request, uri string, update bool) {
|
||||||
var (
|
|
||||||
cachePath = urlToCachePath(uri)
|
|
||||||
cacheHeader = "HIT"
|
|
||||||
logger = log.WithFields(log.Fields{
|
|
||||||
"url": uri,
|
|
||||||
"path": cachePath,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
if strings.HasPrefix(uri, "b64:") {
|
if strings.HasPrefix(uri, "b64:") {
|
||||||
u, err := base64.URLEncoding.DecodeString(strings.TrimPrefix(uri, "b64:"))
|
u, err := base64.URLEncoding.DecodeString(strings.TrimPrefix(uri, "b64:"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,6 +100,15 @@ func handleCache(w http.ResponseWriter, r *http.Request, uri string, update bool
|
||||||
uri = string(u)
|
uri = string(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
cachePath = urlToCachePath(uri)
|
||||||
|
cacheHeader = "HIT"
|
||||||
|
logger = log.WithFields(log.Fields{
|
||||||
|
"url": uri,
|
||||||
|
"path": cachePath,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
if u, err := url.Parse(uri); err != nil || u.Scheme == "" {
|
if u, err := url.Parse(uri); err != nil || u.Scheme == "" {
|
||||||
http.Error(w, "Unable to parse requested URL", http.StatusBadRequest)
|
http.Error(w, "Unable to parse requested URL", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue