aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Mills <prologic@shortcircuit.net.au>2016-09-23 21:36:31 +1000
committerJames Mills <prologic@shortcircuit.net.au>2016-09-23 21:36:31 +1000
commitfb383bcaec715e3f53f5bad6aa9a2881bb698fb3 (patch)
treefe1ad02b2fb1e8fef3e222176d8e9ba4e548e806
parentAdd support for proxying to anywhere in Gopherspace (diff)
downloadgopherproxy-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.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/main.go b/main.go
index 766ece3..4ab9579 100644
--- a/main.go
+++ b/main.go
@@ -16,6 +16,7 @@ import (
16 16
17var ( 17var (
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",