mirror of https://github.com/jlelse/GoBlog
Old HTTPS redirect again
This commit is contained in:
parent
a462566b85
commit
756f6b324c
9
http.go
9
http.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -123,9 +124,13 @@ func shutdownServer(s *http.Server, name string) func() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *goBlog) redirectToHttps(w http.ResponseWriter, r *http.Request) {
|
func (*goBlog) redirectToHttps(w http.ResponseWriter, r *http.Request) {
|
||||||
|
requestHost, _, err := net.SplitHostPort(r.Host)
|
||||||
|
if err != nil {
|
||||||
|
requestHost = r.Host
|
||||||
|
}
|
||||||
w.Header().Set("Connection", "close")
|
w.Header().Set("Connection", "close")
|
||||||
http.Redirect(w, r, fmt.Sprintf("https://%s%s", a.cfg.Server.publicHostname, r.URL.RequestURI()), http.StatusMovedPermanently)
|
http.Redirect(w, r, fmt.Sprintf("https://%s%s", requestHost, r.URL.RequestURI()), http.StatusMovedPermanently)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
Loading…
Reference in New Issue