all repos — fsrv @ ffa051e58ce93755452e18655f74be200bceae0f

filehost server for x.icyphox.sh

Implement bearer authentication
Anirudh Oppiliappan x@icyphox.sh
Wed, 10 Nov 2021 16:39:29 +0530
commit

ffa051e58ce93755452e18655f74be200bceae0f

parent

96aeb8fa8fc95959f40f1a841e88b04e057ef211

1 files changed, 11 insertions(+), 1 deletions(-)

jump to
M main.gomain.go

@@ -31,10 +31,20 @@ }

return string(b) } +func getKey(r *http.Request) string { + var key string + header := r.Header.Get("Authorization") + key = strings.Split(header, " ")[1] + if key == "" { + key = r.FormValue("key") + } + return key +} + func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) { switch r.Method { case "POST": - key := r.FormValue("key") + key := getKey(r) useragent := r.Header.Get("User-Agent") if key != s.key { fmt.Fprintf(w, "incorrect key")