diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2022-05-16 09:20:37 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-05-16 09:20:37 +0300 |
commit | 433eb42cb475239fbc9a9af7be4bff01fc2d0a63 (patch) | |
tree | c254181c923a5723c8bf934d37ac2e357494f55e /internal/domain | |
parent | f21248cf9abd65fde51921593df0ca0017ba4ab6 (diff) | |
parent | 5da5ac23e2757995661e3ac71c7a1011689e0ace (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.go | 11 | ||||
-rw-r--r-- | internal/domain/request_test.go | 7 |
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)) }) } } |