diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-06-22 22:12:49 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-06-22 22:12:49 +0300 |
commit | 4453ff4b08fcbff9955029d8233f75ec1e171760 (patch) | |
tree | d52421a5b5f41b8a1ff80af777f9243bf2397c11 | |
parent | 3fb57b7a2989b50ca4c9543ec86c1f5751cf1a41 (diff) |
Serve 404 if ctx is canceled while resolving a domain
-rw-r--r-- | internal/routing/middleware.go | 6 | ||||
-rw-r--r-- | test/acceptance/serving_test.go | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/internal/routing/middleware.go b/internal/routing/middleware.go index bee7c9df..8272635a 100644 --- a/internal/routing/middleware.go +++ b/internal/routing/middleware.go @@ -1,6 +1,7 @@ package routing import ( + "context" "errors" "net/http" @@ -21,6 +22,11 @@ func NewMiddleware(handler http.Handler, s source.Source) http.Handler { if err != nil && !errors.Is(err, domain.ErrDomainDoesNotExist) { logging.LogRequest(r).WithError(err).Error("could not fetch domain information from a source") + if errors.Is(err, context.Canceled) { + httperrors.Serve404(w) + return + } + httperrors.Serve502(w) return } diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index 92e9c8c7..cf50069d 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -569,7 +569,7 @@ func TestSlowRequests(t *testing.T) { defer cancel() url := httpListener.URL("/index.html") - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) require.NoError(t, err) req.Host = "group.gitlab-example.com" |