Add -url CLI flag for default proxy target and redirect for /

This commit is contained in:
James Mills 2016-09-23 21:36:31 +10:00
parent 8c53aa278f
commit fb383bcaec
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
1 changed files with 6 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import (
var (
bind = flag.String("bind", ":80", "[int]:port to bind to")
uri = flag.String("uri", "127.0.0.1:70", "<host>:[port] to proxy to")
tpl *template.Template
)
@ -67,6 +68,11 @@ func proxy(w http.ResponseWriter, req *http.Request) {
hostport := parts[0]
path := strings.Join(parts[1:], "/")
if len(hostport) == 0 {
http.Redirect(w, req, "/"+*uri, http.StatusFound)
return
}
res, err := gopher.Get(
fmt.Sprintf(
"gopher://%s/%s",