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:
authorMax Wittig <max.wittig@siemens.com>2019-06-28 13:35:29 +0300
committerMax Wittig <max.wittig@siemens.com>2019-07-12 15:37:16 +0300
commit5199c4c8b646f3e66b0f03dd51fbaa704d9fd94f (patch)
treec60baf57319ea68b7b7213c4bba07662ced06d86 /app.go
parent7d39822ce2221156c3479ceae0e4f8e24c7373b2 (diff)
feat: add flag to define custom response headers
Diffstat (limited to 'app.go')
-rw-r--r--app.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/app.go b/app.go
index 7e73e700..2cb8bbd9 100644
--- a/app.go
+++ b/app.go
@@ -23,6 +23,7 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/admin"
"gitlab.com/gitlab-org/gitlab-pages/internal/artifact"
"gitlab.com/gitlab-org/gitlab-pages/internal/auth"
+ headerConfig "gitlab.com/gitlab-org/gitlab-pages/internal/config"
"gitlab.com/gitlab-org/gitlab-pages/internal/domain"
"gitlab.com/gitlab-org/gitlab-pages/internal/httperrors"
"gitlab.com/gitlab-org/gitlab-pages/internal/netutil"
@@ -51,6 +52,7 @@ type theApp struct {
Artifact *artifact.Artifact
Auth *auth.Auth
AcmeMiddleware *acme.Middleware
+ CustomHeaders http.Header
}
func (a *theApp) isReady() bool {
@@ -229,6 +231,8 @@ func (a *theApp) serveFileOrNotFound(domain *domain.D) http.HandlerFunc {
func (a *theApp) ServeHTTP(ww http.ResponseWriter, r *http.Request) {
https := r.TLS != nil
+ headerConfig.AddCustomHeaders(ww, a.CustomHeaders)
+
a.serveContent(ww, r, https)
}
@@ -239,6 +243,7 @@ func (a *theApp) ServeProxy(ww http.ResponseWriter, r *http.Request) {
if forwardedHost := r.Header.Get(xForwardedHost); forwardedHost != "" {
r.Host = forwardedHost
}
+ headerConfig.AddCustomHeaders(ww, a.CustomHeaders)
a.serveContent(ww, r, https)
}
@@ -380,6 +385,14 @@ func runApp(config appConfig) {
a.AcmeMiddleware = &acme.Middleware{GitlabURL: config.GitLabServer}
}
+ if len(config.CustomHeaders) != 0 {
+ customHeaders, err := headerConfig.ParseHeaderString(config.CustomHeaders)
+ if err != nil {
+ log.Fatal(err)
+ }
+ a.CustomHeaders = customHeaders
+ }
+
configureLogging(config.LogFormat, config.LogVerbose)
if err := mimedb.LoadTypes(); err != nil {