Skip to content

Commit 334a9ec

Browse files
authored
Small fix to prevent panic when --address not provided with --ssl and --port (#431)
kudos to Michail Kovtun for reporting it
1 parent c91a1dd commit 334a9ec

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ func main() {
9494
pos := strings.IndexByte(addr, ':')
9595
rediraddr := addr[:pos] + ":" + strconv.Itoa(config.RedirPort) // it would be silly to optimize this one
9696
redir := &http.Server{Addr: rediraddr, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
97-
9897
// redirect to same hostname as in request but different port and probably schema
9998
uri := "https://"
10099
if !config.Ssl {
101100
uri = "http://"
102101
}
103-
uri += r.Host[:strings.IndexByte(r.Host, ':')] + addr[pos:] + "/"
102+
if cpos := strings.IndexByte(r.Host, ':'); cpos > 0 {
103+
uri += r.Host[:strings.IndexByte(r.Host, ':')] + addr[pos:] + "/"
104+
} else {
105+
uri += r.Host + addr[pos:] + "/"
106+
}
104107

105108
http.Redirect(w, r, uri, http.StatusMovedPermanently)
106109
})}

0 commit comments

Comments
 (0)