[BREAKING] added entrypoint middleware support and config, config schema update

This commit is contained in:
yusing
2024-11-30 08:02:03 +08:00
parent 3af3a88f66
commit 1c1ba1b55e
9 changed files with 274 additions and 74 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors"
"io"
"log"
"net"
"net/http"
"time"
@@ -57,7 +58,11 @@ func NewServer(opt Options) (s *Server) {
}
if certAvailable && opt.RedirectToHTTPS && opt.HTTPSAddr != "" {
httpHandler = redirectToTLSHandler(opt.HTTPSAddr)
_, port, err := net.SplitHostPort(opt.HTTPSAddr)
if err != nil {
panic(err)
}
httpHandler = redirectToTLSHandler(port)
} else {
httpHandler = opt.Handler
}
@@ -151,7 +156,7 @@ func (s *Server) handleErr(scheme string, err error) {
func redirectToTLSHandler(port string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
r.URL.Scheme = "https"
r.URL.Host = r.URL.Hostname() + port
r.URL.Host = r.URL.Hostname() + ":" + port
var redirectCode int
if r.Method == http.MethodGet {