diff options
author | Adnan Maolood <me@adnano.co> | 2021-02-24 23:29:15 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2021-02-25 08:52:21 -0500 |
commit | 60109be26fb5058d543d0842ac77d78ee8faad7b (patch) | |
tree | ff4b7703a89b30d5c8f1633600c49c2ed13224f2 | |
parent | Use fmt.Fprintf instead of Write and Sprintf (diff) | |
download | kineto-60109be26fb5058d543d0842ac77d78ee8faad7b.tar.bz2 kineto-60109be26fb5058d543d0842ac77d78ee8faad7b.zip |
Implement input prompts on external domains
-rw-r--r-- | main.go | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -579,6 +579,19 @@ func main() { })) http.Handle("/x/", 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 + } + if r.Method != "GET" { w.WriteHeader(http.StatusMethodNotAllowed) w.Write([]byte("404 Not found")) @@ -590,14 +603,13 @@ func main() { path = append(path, "") } req := gemini.Request{} - req.URL, err = url.Parse(fmt.Sprintf("gemini://%s/%s", path[2], path[3])) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("Error: %v", err))) - return - } + req.URL = &url.URL{} + req.URL.Scheme = "gemini" + req.URL.Host = path[2] + req.URL.Path = "/" + path[3] req.Host = path[2] - log.Printf("%s (external) %s%s", r.Method, path[2], path[3]) + req.URL.RawQuery = r.URL.RawQuery + log.Printf("%s (external) %s%s", r.Method, r.URL.Host, r.URL.Path) proxyGemini(req, true, root, w, r, css) })) |