diff options
| author | James Mills <prologic@shortcircuit.net.au> | 2016-09-23 21:36:31 +1000 |
|---|---|---|
| committer | James Mills <prologic@shortcircuit.net.au> | 2016-09-23 21:36:31 +1000 |
| commit | fb383bcaec715e3f53f5bad6aa9a2881bb698fb3 (patch) | |
| tree | fe1ad02b2fb1e8fef3e222176d8e9ba4e548e806 | |
| parent | Add support for proxying to anywhere in Gopherspace (diff) | |
| download | gopherproxy-fb383bcaec715e3f53f5bad6aa9a2881bb698fb3.tar.gz gopherproxy-fb383bcaec715e3f53f5bad6aa9a2881bb698fb3.tar.bz2 gopherproxy-fb383bcaec715e3f53f5bad6aa9a2881bb698fb3.zip | |
Add -url CLI flag for default proxy target and redirect for /
| -rw-r--r-- | main.go | 6 |
1 files changed, 6 insertions, 0 deletions
| @@ -16,6 +16,7 @@ import ( | |||
| 16 | 16 | ||
| 17 | var ( | 17 | var ( |
| 18 | bind = flag.String("bind", ":80", "[int]:port to bind to") | 18 | bind = flag.String("bind", ":80", "[int]:port to bind to") |
| 19 | uri = flag.String("uri", "127.0.0.1:70", "<host>:[port] to proxy to") | ||
| 19 | 20 | ||
| 20 | tpl *template.Template | 21 | tpl *template.Template |
| 21 | ) | 22 | ) |
| @@ -67,6 +68,11 @@ func proxy(w http.ResponseWriter, req *http.Request) { | |||
| 67 | hostport := parts[0] | 68 | hostport := parts[0] |
| 68 | path := strings.Join(parts[1:], "/") | 69 | path := strings.Join(parts[1:], "/") |
| 69 | 70 | ||
| 71 | if len(hostport) == 0 { | ||
| 72 | http.Redirect(w, req, "/"+*uri, http.StatusFound) | ||
| 73 | return | ||
| 74 | } | ||
| 75 | |||
| 70 | res, err := gopher.Get( | 76 | res, err := gopher.Get( |
| 71 | fmt.Sprintf( | 77 | fmt.Sprintf( |
| 72 | "gopher://%s/%s", | 78 | "gopher://%s/%s", |
