1
0
Fork 0
mirror of https://github.com/Luzifer/preserve.git synced 2024-11-08 14:20:05 +00:00

Handle base64 encoded URIs

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-05 16:05:02 +01:00
parent 222c0a7d63
commit 4206f2719d
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

10
main.go
View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"encoding/base64"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -99,6 +100,15 @@ func handleCache(w http.ResponseWriter, r *http.Request, uri string, update bool
}) })
) )
if strings.HasPrefix(uri, "b64:") {
u, err := base64.URLEncoding.DecodeString(strings.TrimPrefix(uri, "b64:"))
if err != nil {
http.Error(w, "Unable to decode base64 URL", http.StatusBadRequest)
return
}
uri = string(u)
}
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