From 182e86f5bb9b89c0b17f23c7f5739463ffbdf5bb 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gateway/errors.go b/gateway/errors.go index 08b532e82..4487f0c2e 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,10 @@ 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 + return strings.Contains(err.Error(), "blocked and cannot be provided") +}