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>2022-05-16 09:20:37 +0300
committerJaime Martinez <jmartinez@gitlab.com>2022-05-16 09:20:37 +0300
commit433eb42cb475239fbc9a9af7be4bff01fc2d0a63 (patch)
treec254181c923a5723c8bf934d37ac2e357494f55e /internal/domain
parentf21248cf9abd65fde51921593df0ca0017ba4ab6 (diff)
parent5da5ac23e2757995661e3ac71c7a1011689e0ace (diff)
Merge branch 'refactor/abstract-artifact-middleware' into 'master'
refactor: move artifact resolution to a separate middleware See merge request gitlab-org/gitlab-pages!765
Diffstat (limited to 'internal/domain')
-rw-r--r--internal/domain/request.go11
-rw-r--r--internal/domain/request_test.go7
2 files changed, 3 insertions, 15 deletions
diff --git a/internal/domain/request.go b/internal/domain/request.go
index a10218ed..c6318922 100644
--- a/internal/domain/request.go
+++ b/internal/domain/request.go
@@ -8,24 +8,17 @@ import (
type ctxKey string
const (
- ctxHostKey ctxKey = "host"
ctxDomainKey ctxKey = "domain"
)
-// ReqWithHostAndDomain saves host name and domain in the request's context
-func ReqWithHostAndDomain(r *http.Request, host string, domain *Domain) *http.Request {
+// ReqWithDomain saves domain in the request's context
+func ReqWithDomain(r *http.Request, domain *Domain) *http.Request {
ctx := r.Context()
- ctx = context.WithValue(ctx, ctxHostKey, host)
ctx = context.WithValue(ctx, ctxDomainKey, domain)
return r.WithContext(ctx)
}
-// GetHost extracts the host from request's context
-func GetHost(r *http.Request) string {
- return r.Context().Value(ctxHostKey).(string)
-}
-
// FromRequest extracts the domain from request's context
func FromRequest(r *http.Request) *Domain {
return r.Context().Value(ctxDomainKey).(*Domain)
diff --git a/internal/domain/request_test.go b/internal/domain/request_test.go
index c261d1f7..3ed82baa 100644
--- a/internal/domain/request_test.go
+++ b/internal/domain/request_test.go
@@ -12,10 +12,6 @@ func TestPanics(t *testing.T) {
require.NoError(t, err)
require.Panics(t, func() {
- GetHost(r)
- })
-
- require.Panics(t, func() {
FromRequest(r)
})
}
@@ -42,9 +38,8 @@ func TestWithHostAndDomain(t *testing.T) {
r, err := http.NewRequest("GET", "/", nil)
require.NoError(t, err)
- r = ReqWithHostAndDomain(r, tt.host, tt.domain)
+ r = ReqWithDomain(r, tt.domain)
require.Exactly(t, tt.domain, FromRequest(r))
- require.Equal(t, tt.host, GetHost(r))
})
}
}