aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnirudh Oppiliappan <x@icyphox.sh>2021-08-06 17:49:38 +0530
committerAnirudh Oppiliappan <x@icyphox.sh>2021-08-06 17:49:38 +0530
commit935cd56cdb007397f802d5f870f1c08496d87d19 (patch)
tree59c72ccf8463cb4a2649c9d4c7b0389772117223
parentf2531467f400563a56c2192b34815d07b97ed9ed (diff)
downloadfsrv-935cd56cdb007397f802d5f870f1c08496d87d19.tar.gz
Redirect if User-Agent is not curl
-rw-r--r--main.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/main.go b/main.go
index 29d6b8f..f521dc1 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
9 "net/http" 9 "net/http"
10 "os" 10 "os"
11 "path/filepath" 11 "path/filepath"
12 "strings"
12 "time" 13 "time"
13) 14)
14 15
@@ -34,6 +35,7 @@ func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) {
34 switch r.Method { 35 switch r.Method {
35 case "POST": 36 case "POST":
36 key := r.FormValue("key") 37 key := r.FormValue("key")
38 useragent := r.Header.Get("User-Agent")
37 fmt.Println(key) 39 fmt.Println(key)
38 if key != s.key { 40 if key != s.key {
39 fmt.Fprintf(w, "incorrect key") 41 fmt.Fprintf(w, "incorrect key")
@@ -61,7 +63,11 @@ func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) {
61 log.Printf("wrote: %+v", diskFile) 63 log.Printf("wrote: %+v", diskFile)
62 64
63 fileUrl := s.url + "/" + newFile 65 fileUrl := s.url + "/" + newFile
64 fmt.Fprintf(w, "%v", fileUrl) 66 if strings.Contains(useragent, "curl/") {
67 fmt.Fprintf(w, "%v", fileUrl)
68 } else {
69 http.Redirect(w, r, fileUrl, http.StatusSeeOther)
70 }
65 case "GET": 71 case "GET":
66 http.ServeFile(w, r, s.index) 72 http.ServeFile(w, r, s.index)
67 default: 73 default: