diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-05-04 00:30:34 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-05-05 13:57:09 +0300 |
commit | 5da5ac23e2757995661e3ac71c7a1011689e0ace (patch) | |
tree | b94c3c93c6ea653cbccc003f80f35b9514593629 /internal/routing/middleware.go | |
parent | 40528a5463f155f70d33dac3573199c0ba3e599d (diff) |
Abstract artifact handling to a separate middleware
Diffstat (limited to 'internal/routing/middleware.go')
-rw-r--r-- | internal/routing/middleware.go | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/internal/routing/middleware.go b/internal/routing/middleware.go index de34ec21..712e22a3 100644 --- a/internal/routing/middleware.go +++ b/internal/routing/middleware.go @@ -18,7 +18,7 @@ func NewMiddleware(handler http.Handler, s source.Source) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // if we could not retrieve a domain from domains source we break the // middleware chain and simply respond with 502 after logging this - host, d, err := getHostAndDomain(r, s) + d, err := getDomain(r, s) if err != nil && !errors.Is(err, domain.ErrDomainDoesNotExist) { metrics.DomainsSourceFailures.Inc() logging.LogRequest(r).WithError(err).Error("could not fetch domain information from a source") @@ -27,15 +27,13 @@ func NewMiddleware(handler http.Handler, s source.Source) http.Handler { return } - r = domain.ReqWithHostAndDomain(r, host, d) + r = domain.ReqWithDomain(r, d) handler.ServeHTTP(w, r) }) } -func getHostAndDomain(r *http.Request, s source.Source) (string, *domain.Domain, error) { +func getDomain(r *http.Request, s source.Source) (*domain.Domain, error) { host := request.GetHostWithoutPort(r) - domain, err := s.GetDomain(r.Context(), host) - - return host, domain, err + return s.GetDomain(r.Context(), host) } |