diff options
| author | Drew DeVault <[email protected]> | 2020-11-08 12:41:56 -0500 |
|---|---|---|
| committer | Drew DeVault <[email protected]> | 2020-11-08 12:41:56 -0500 |
| commit | 44390b2513d1ac8d20cb5d5a5325574d7a6fea1f (patch) | |
| tree | ebe35032ae89781e1a07fbae537561e4d0d11b97 | |
| parent | Fix URLs with legit query strings in them (diff) | |
| download | capybara-44390b2513d1ac8d20cb5d5a5325574d7a6fea1f.tar.xz capybara-44390b2513d1ac8d20cb5d5a5325574d7a6fea1f.zip | |
Use POST request to respond to input requests
| -rw-r--r-- | main.go | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -232,7 +232,7 @@ var inputPage = template.Must(template. </style> {{- end }} <title>{{.Prompt}}</title> -<form> +<form method="POST"> <label for="input">{{.Prompt}}</label> {{ if .Secret }} <input type="password" id="input" name="q" /> @@ -523,6 +523,19 @@ func main() { } http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == "POST" { + r.ParseForm() + if q, ok := r.Form["q"]; !ok { + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("Bad request")) + } else { + w.Header().Add("Location", "?" + q[0]) + w.WriteHeader(http.StatusFound) + w.Write([]byte("Redirecting")) + } + return + } + log.Printf("%s %s", r.Method, r.URL.Path) if r.Method != "GET" { w.WriteHeader(http.StatusMethodNotAllowed) @@ -542,12 +555,7 @@ func main() { req.URL.Host = root.Host req.URL.Path = r.URL.Path req.Host = root.Host - q := r.URL.Query() - if x, ok := q["q"]; ok { - req.URL.RawQuery = x[0] - } else { - req.URL.RawQuery = r.URL.RawQuery - } + req.URL.RawQuery = r.URL.RawQuery proxyGemini(req, false, root, w, r) })) |