diff options
-rw-r--r-- | main.go | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -31,10 +31,20 @@ func randName(n int) string { | |||
31 | return string(b) | 31 | return string(b) |
32 | } | 32 | } |
33 | 33 | ||
34 | func getKey(r *http.Request) string { | ||
35 | var key string | ||
36 | header := r.Header.Get("Authorization") | ||
37 | key = strings.Split(header, " ")[1] | ||
38 | if key == "" { | ||
39 | key = r.FormValue("key") | ||
40 | } | ||
41 | return key | ||
42 | } | ||
43 | |||
34 | func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) { | 44 | func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) { |
35 | switch r.Method { | 45 | switch r.Method { |
36 | case "POST": | 46 | case "POST": |
37 | key := r.FormValue("key") | 47 | key := getKey(r) |
38 | useragent := r.Header.Get("User-Agent") | 48 | useragent := r.Header.Get("User-Agent") |
39 | if key != s.key { | 49 | if key != s.key { |
40 | fmt.Fprintf(w, "incorrect key") | 50 | fmt.Fprintf(w, "incorrect key") |