Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2022-04-20 18:57:30 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2022-04-20 18:57:30 +0300
commit60864cb8ebd9b79abc57fd29d21241cdacb21efd (patch)
treeee4a753189c5b54a9c5e90e06f1558089a5ba10d /app.go
parentdabfd71101d4598f31ab474f6a7bfc75bfa0a045 (diff)
Add early https redirect
Diffstat (limited to 'app.go')
-rw-r--r--app.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/app.go b/app.go
index 4f187f9d..12228c53 100644
--- a/app.go
+++ b/app.go
@@ -117,12 +117,6 @@ func (a *theApp) checkAuthAndServeNotFound(domain *domain.Domain, w http.Respons
}
func (a *theApp) tryAuxiliaryHandlers(w http.ResponseWriter, r *http.Request, https bool, host string, domain *domain.Domain) bool {
- // Add auto redirect
- if !https && a.config.General.RedirectHTTP {
- a.redirectToHTTPS(w, r, http.StatusTemporaryRedirect)
- return true
- }
-
if a.Handlers.HandleArtifactRequest(host, w, r) {
return true
}
@@ -188,6 +182,17 @@ func (a *theApp) auxiliaryMiddleware(handler http.Handler) http.Handler {
})
}
+func (a *theApp) httpsRedirectMiddleware(handler http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if a.config.General.RedirectHTTP && !request.IsHTTPS(r) {
+ a.redirectToHTTPS(w, r, http.StatusTemporaryRedirect)
+ return
+ }
+
+ handler.ServeHTTP(w, r)
+ })
+}
+
// serveFileOrNotFoundHandler will serve static content or
// return a 404 Not Found response
func (a *theApp) serveFileOrNotFoundHandler() http.Handler {
@@ -255,6 +260,9 @@ func (a *theApp) buildHandlerPipeline() (http.Handler, error) {
// Custom response headers
handler = customheaders.NewMiddleware(handler, a.CustomHeaders)
+ // Add auto redirect
+ handler = a.httpsRedirectMiddleware(handler)
+
// Correlation ID injection middleware
var correlationOpts []correlation.InboundHandlerOption
if a.config.General.PropagateCorrelationID {