gopherproxy

(mirror) Gopher (RFC 1436) Web Proxy
git clone git://tx.god.jp/gopherproxy.git
Log | Files | Refs | LICENSE

commit 0105bbb0d56f4ca845df1b73cd2a0b8e94a968ae
parent 669492455bba0426fdb30dec650c94a8744b926b
Author: James Mills <prologic@shortcircuit.net.au>
Date:   Fri, 23 Sep 2016 00:02:59 +1000

Add query support

Diffstat:
main.go | 20+++++++++++++++-----
template.go | 14+++++++++++++-
2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/main.go b/main.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "log" "net/http" + "net/url" "strings" "github.com/prologic/go-gopher" @@ -17,6 +18,8 @@ var ( bind = flag.String("bind", ":80", "[int]:port to bind to") host = flag.String("host", "localhost", "host to proxy to") port = flag.Int("port", 70, "port to proxy to") + + tpl *template.Template ) type tplRow struct { @@ -44,7 +47,9 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, d gopher.Dir } else { tr.Link = template.URL( fmt.Sprintf( - "%s%s", string(byte(x.Type)), x.Selector, + "/%s%s", + string(byte(x.Type)), + url.QueryEscape(x.Selector), ), ) } @@ -55,13 +60,20 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, d gopher.Dir return tpl.Execute(w, struct { Title string Lines []tplRow - }{"XXX", out}) + }{*host, out}) } func proxy(w http.ResponseWriter, req *http.Request) { path := strings.TrimPrefix(req.URL.Path, "/") - res, err := gopher.Get(fmt.Sprintf("gopher://%s:%d/%s", *host, *port, path)) + res, err := gopher.Get( + fmt.Sprintf( + "gopher://%s:%d/%s", + *host, + *port, + url.QueryEscape(path), + ), + ) if err != nil { io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) return @@ -77,8 +89,6 @@ func proxy(w http.ResponseWriter, req *http.Request) { } } -var tpl *template.Template - func main() { flag.Parse() diff --git a/template.go b/template.go @@ -8,7 +8,19 @@ var tpltext = `<!doctype html> </head> <body> <pre> -{{range .Lines}} {{if .Link}}({{.Type}}) <a href="{{.Link}}">{{.Text}}</a>{{else}} {{.Text}}{{end}} +{{range .Lines}} {{if .Link}}({{.Type}}) <a class="{{ .Type }}" href="{{.Link}}">{{.Text}}</a>{{else}} {{.Text}}{{end}} {{end}}</pre> +<script src="https://code.jquery.com/jquery-3.1.0.slim.min.js" integrity="sha256-cRpWjoSOw5KcyIOaZNo4i6fZ9tKPhYYb6i5T9RSVJG8=" crossorigin="anonymous"></script> +<script type="text/javascript"> +$(document).ready(function () { + $(".QRY").click(function (e) { + e.preventDefault(); + var query = prompt("Please enter required input: ", ""); + if (query != null) { + window.location = e.target.href + "%09" + query; + } + }); +}); +</script> </body> </html>`