Skip to content

Commit

Permalink
Small fix to prevent panic when --address not provided with --ssl and…
Browse files Browse the repository at this point in the history
… --port (joewalnes#431)

kudos to Michail Kovtun for reporting it
  • Loading branch information
asergeyev committed Nov 4, 2022
1 parent c91a1dd commit 334a9ec
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,16 @@ func main() {
pos := strings.IndexByte(addr, ':')
rediraddr := addr[:pos] + ":" + strconv.Itoa(config.RedirPort) // it would be silly to optimize this one
redir := &http.Server{Addr: rediraddr, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

// redirect to same hostname as in request but different port and probably schema
uri := "https://"
if !config.Ssl {
uri = "http://"
}
uri += r.Host[:strings.IndexByte(r.Host, ':')] + addr[pos:] + "/"
if cpos := strings.IndexByte(r.Host, ':'); cpos > 0 {
uri += r.Host[:strings.IndexByte(r.Host, ':')] + addr[pos:] + "/"
} else {
uri += r.Host + addr[pos:] + "/"
}

http.Redirect(w, r, uri, http.StatusMovedPermanently)
})}
Expand Down

0 comments on commit 334a9ec

Please sign in to comment.