diff options
-rw-r--r-- | gopherproxy.go | 16 | ||||
-rw-r--r-- | template.go | 2 |
2 files changed, 14 insertions, 4 deletions
diff --git a/gopherproxy.go b/gopherproxy.go index 4a2255f..8c85448 100644 --- a/gopherproxy.go +++ b/gopherproxy.go | |||
@@ -45,7 +45,7 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport str | |||
45 | } else { | 45 | } else { |
46 | hostport = fmt.Sprintf("%s:%d", x.Host, x.Port) | 46 | hostport = fmt.Sprintf("%s:%d", x.Host, x.Port) |
47 | } | 47 | } |
48 | path := url.QueryEscape(x.Selector) | 48 | path := url.PathEscape(x.Selector) |
49 | path = strings.Replace(path, "%2F", "/", -1) | 49 | path = strings.Replace(path, "%2F", "/", -1) |
50 | tr.Link = template.URL( | 50 | tr.Link = template.URL( |
51 | fmt.Sprintf( | 51 | fmt.Sprintf( |
@@ -73,25 +73,35 @@ func MakeGopherProxyHandler(tpl *template.Template, uri string) Handler { | |||
73 | return func(w http.ResponseWriter, req *http.Request) { | 73 | return func(w http.ResponseWriter, req *http.Request) { |
74 | parts := strings.Split(strings.TrimPrefix(req.URL.Path, "/"), "/") | 74 | parts := strings.Split(strings.TrimPrefix(req.URL.Path, "/"), "/") |
75 | hostport := parts[0] | 75 | hostport := parts[0] |
76 | path := strings.Join(parts[1:], "/") | ||
77 | 76 | ||
78 | if len(hostport) == 0 { | 77 | if len(hostport) == 0 { |
79 | http.Redirect(w, req, "/"+uri, http.StatusFound) | 78 | http.Redirect(w, req, "/"+uri, http.StatusFound) |
80 | return | 79 | return |
81 | } | 80 | } |
82 | 81 | ||
82 | var qs string | ||
83 | |||
84 | path := strings.Join(parts[1:], "/") | ||
85 | |||
86 | if req.URL.RawQuery != "" { | ||
87 | qs = fmt.Sprintf("?%s", url.QueryEscape(req.URL.RawQuery)) | ||
88 | } | ||
89 | |||
83 | uri, err := url.QueryUnescape(path) | 90 | uri, err := url.QueryUnescape(path) |
84 | if err != nil { | 91 | if err != nil { |
85 | io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) | 92 | io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) |
86 | return | 93 | return |
87 | } | 94 | } |
95 | |||
88 | res, err := gopher.Get( | 96 | res, err := gopher.Get( |
89 | fmt.Sprintf( | 97 | fmt.Sprintf( |
90 | "gopher://%s/%s", | 98 | "gopher://%s/%s%s", |
91 | hostport, | 99 | hostport, |
92 | uri, | 100 | uri, |
101 | qs, | ||
93 | ), | 102 | ), |
94 | ) | 103 | ) |
104 | |||
95 | if err != nil { | 105 | if err != nil { |
96 | io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) | 106 | io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) |
97 | return | 107 | return |
diff --git a/template.go b/template.go index 604f380..6fb1162 100644 --- a/template.go +++ b/template.go | |||
@@ -22,7 +22,7 @@ $(document).ready(function () { | |||
22 | e.preventDefault(); | 22 | e.preventDefault(); |
23 | var query = prompt("Please enter required input: ", ""); | 23 | var query = prompt("Please enter required input: ", ""); |
24 | if (query != null) { | 24 | if (query != null) { |
25 | window.location = e.target.href + "%09" + query; | 25 | window.location = e.target.href + "?" + query; |
26 | } | 26 | } |
27 | }); | 27 | }); |
28 | }); | 28 | }); |