Redirect if User-Agent is not curl
Anirudh Oppiliappan x@icyphox.sh
Fri, 06 Aug 2021 17:49:38 +0530
1 files changed,
7 insertions(+),
1 deletions(-)
jump to
M
main.go
→
main.go
@@ -9,6 +9,7 @@ "math/rand"
"net/http" "os" "path/filepath" + "strings" "time" )@@ -34,6 +35,7 @@ func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) {
switch r.Method { case "POST": key := r.FormValue("key") + useragent := r.Header.Get("User-Agent") fmt.Println(key) if key != s.key { fmt.Fprintf(w, "incorrect key")@@ -61,7 +63,11 @@ os.WriteFile(diskFile, fileBytes, 0644)
log.Printf("wrote: %+v", diskFile) fileUrl := s.url + "/" + newFile - fmt.Fprintf(w, "%v", fileUrl) + if strings.Contains(useragent, "curl/") { + fmt.Fprintf(w, "%v", fileUrl) + } else { + http.Redirect(w, r, fileUrl, http.StatusSeeOther) + } case "GET": http.ServeFile(w, r, s.index) default: