From 72da286aaa8d69bbc988b734afe7e469524334a8 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Sat, 28 Oct 2023 03:52:56 +0200 Subject: [PATCH] fix(gw): blocked content produces http error 410 this is the minimum we need right now to make content blocking from https://github.com/ipfs/kubo/pull/10161 return HTTP 410 on rule match --- gateway/errors.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gateway/errors.go b/gateway/errors.go index 08b532e82..9632d94e1 100644 --- a/gateway/errors.go +++ b/gateway/errors.go @@ -149,6 +149,8 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa code = http.StatusBadRequest case isErrNotFound(err): code = http.StatusNotFound + case isErrContentBlocked(err): + code = http.StatusGone case errors.Is(err, context.DeadlineExceeded): code = http.StatusGatewayTimeout } @@ -202,3 +204,13 @@ func isErrNotFound(err error) bool { } } } + +// isErrContentBlocked returns true for content filtering system errors +func isErrContentBlocked(err error) bool { + // TODO: we match error message to avoid pulling nopfs as a dependency + // Ref. https://github.com/ipfs-shipyard/nopfs/blob/cde3b5ba964c13e977f4a95f3bd8ca7d7710fbda/status.go#L87-L89 + if strings.Contains(err.Error(), "blocked and cannot be provided") { + return true + } + return false +}