mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 07:43:17 +00:00
caddyhttp: Redirect HTTP requests on the HTTPS port to https:// (#4313)
* caddyhttp: Redirect HTTP requests on the HTTPS port to https:// * Apply suggestions from code review Co-authored-by: Matt Holt <mholt@users.noreply.github.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
b4bfa29be2
commit
80d7a356b3
2 changed files with 119 additions and 0 deletions
|
@ -343,6 +343,11 @@ func (app *App) Start() error {
|
|||
// enable TLS if there is a policy and if this is not the HTTP port
|
||||
useTLS := len(srv.TLSConnPolicies) > 0 && int(listenAddr.StartPort+portOffset) != app.httpPort()
|
||||
if useTLS {
|
||||
// create HTTP redirect wrapper, which detects if
|
||||
// the request had HTTP bytes on the HTTPS port, and
|
||||
// triggers a redirect if so.
|
||||
ln = &httpRedirectListener{Listener: ln}
|
||||
|
||||
// create TLS listener
|
||||
tlsCfg := srv.TLSConnPolicies.TLSConfig(app.ctx)
|
||||
ln = tls.NewListener(ln, tlsCfg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue