Add -url CLI flag for default proxy target and redirect for /
This commit is contained in:
parent
8c53aa278f
commit
fb383bcaec
6
main.go
6
main.go
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue