-
- Notifications
You must be signed in to change notification settings - Fork 6.2k
Add an option to allow redirect of http port 80 to https. #1928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -51,6 +51,26 @@ and it takes care of all the other things for you`, | |
}, | ||
} | ||
| ||
func runHTTPRedirector() { | ||
source := fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.PortToRedirect) | ||
dest := strings.TrimSuffix(setting.AppURL, "/") | ||
log.Info("Redirecting: %s to %s", source, dest) | ||
| ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
target := dest + r.URL.Path | ||
if len(r.URL.RawQuery) > 0 { | ||
target += "?" + r.URL.RawQuery | ||
} | ||
http.Redirect(w, r, target, http.StatusTemporaryRedirect) | ||
}) | ||
| ||
| ||
var err = runHTTP(source, context2.ClearHandler(handler)) | ||
| ||
if err != nil { | ||
log.Fatal(4, "Failed to start port redirection: %v", err) | ||
} | ||
} | ||
| ||
func runWeb(ctx *cli.Context) error { | ||
if ctx.IsSet("config") { | ||
setting.CustomConf = ctx.String("config") | ||
| @@ -124,6 +144,9 @@ func runWeb(ctx *cli.Context) error { | |
case setting.HTTP: | ||
err = runHTTP(listenAddr, context2.ClearHandler(m)) | ||
case setting.HTTPS: | ||
if setting.RedirectOtherPort { | ||
go runHTTPRedirector() | ||
} | ||
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m)) | ||
case setting.FCGI: | ||
listener, err := net.Listen("tcp", listenAddr) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Temporary and not Permanent? Then webbrowsers can go to https automagically afterwards even if they type http 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary redirect also supports POST. I based the redirect logic on this gist: https://gist.github.com/d-schmidt/587ceec34ce1334a5e60
I don't have strong feelings about this either way. It felt more complete to support any type of request. Chrome seems to treat temporary in a similar manner as permanent. Presumably it is doing so with some kind of cache timeout, so you would go back to the http address after a period of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. LGTM