cmd/web: write URL to client instead of forwarding client

Signed-off-by: Xe Iaso <xe@tailscale.com>
This commit is contained in:
Xe Iaso 2022-12-08 20:38:02 +00:00
parent b397291bd2
commit 5184d9337f

View file

@ -141,7 +141,15 @@ WHERE p.id = ?1`
return
}
err = r.ParseMultipartForm(formDataLimit)
if strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data;") {
err = r.ParseMultipartForm(formDataLimit)
} else if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
err = r.ParseForm()
} else {
log.Printf("%s: unknown content type: %s", r.RemoteAddr, r.Header.Get("Content-Type"))
http.Error(w, "bad content-type, should be a form", http.StatusBadRequest)
return
}
if err != nil {
log.Printf("%s: bad form: %v", r.RemoteAddr, err)
http.Error(w, err.Error(), http.StatusBadRequest)
@ -186,7 +194,10 @@ VALUES
return
}
http.Redirect(w, r, "/paste/"+id, http.StatusTemporaryRedirect)
log.Printf("new paste: %s", id)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "http://%s/paste/%s", r.Host, id)
})
log.Printf("listening on http://%s", *hostname)