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
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-11-16 05:56:22 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-11-30 02:15:09 +0300
commite59ec12bcc06b10860c811bc3810a6320b9855d2 (patch)
tree02e52e3d988ec6cf24415f64b5a73798df2af7a2
parent188a44eba522c23110897ac6fb1091a68680db4e (diff)
Move headers to middleware
-rw-r--r--app.go6
-rw-r--r--internal/middleware/headers.go (renamed from internal/config/headers.go)5
-rw-r--r--internal/middleware/headers_test.go (renamed from internal/config/headers_test.go)2
3 files changed, 6 insertions, 7 deletions
diff --git a/app.go b/app.go
index ca495073..a802f96d 100644
--- a/app.go
+++ b/app.go
@@ -21,11 +21,11 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/acme"
"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/handlers"
"gitlab.com/gitlab-org/gitlab-pages/internal/httperrors"
"gitlab.com/gitlab-org/gitlab-pages/internal/logging"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/middleware"
"gitlab.com/gitlab-org/gitlab-pages/internal/netutil"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
"gitlab.com/gitlab-org/gitlab-pages/internal/source"
@@ -186,7 +186,7 @@ func (a *theApp) healthCheckMiddleware(handler http.Handler) (http.Handler, erro
// customHeadersMiddleware will inject custom headers into the response
func (a *theApp) customHeadersMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- headerConfig.AddCustomHeaders(w, a.CustomHeaders)
+ middleware.AddCustomHeaders(w, a.CustomHeaders)
handler.ServeHTTP(w, r)
})
@@ -493,7 +493,7 @@ func runApp(config appConfig) {
}
if len(config.CustomHeaders) != 0 {
- customHeaders, err := headerConfig.ParseHeaderString(config.CustomHeaders)
+ customHeaders, err := middleware.ParseHeaderString(config.CustomHeaders)
if err != nil {
log.WithError(err).Fatal("Unable to parse header string")
}
diff --git a/internal/config/headers.go b/internal/middleware/headers.go
index d415b21d..77b008f3 100644
--- a/internal/config/headers.go
+++ b/internal/middleware/headers.go
@@ -1,4 +1,4 @@
-package config
+package middleware
import (
"errors"
@@ -9,13 +9,12 @@ import (
var errInvalidHeaderParameter = errors.New("invalid syntax specified as header parameter")
// AddCustomHeaders adds a map of Headers to a Response
-func AddCustomHeaders(w http.ResponseWriter, headers http.Header) error {
+func AddCustomHeaders(w http.ResponseWriter, headers http.Header) {
for k, v := range headers {
for _, value := range v {
w.Header().Add(k, value)
}
}
- return nil
}
// ParseHeaderString parses a string of key values into a map
diff --git a/internal/config/headers_test.go b/internal/middleware/headers_test.go
index 44afd470..17d31b50 100644
--- a/internal/config/headers_test.go
+++ b/internal/middleware/headers_test.go
@@ -1,4 +1,4 @@
-package config
+package middleware
import (
"net/http/httptest"