mirror of
https://github.com/Luzifer/preserve.git
synced 2024-12-20 09:41:18 +00:00
Handle base64 encoded URIs
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
222c0a7d63
commit
4206f2719d
1 changed files with 10 additions and 0 deletions
10
main.go
10
main.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"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 == "" {
|
||||
http.Error(w, "Unable to parse requested URL", http.StatusBadRequest)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue