Skip to content

Commit 182e86f

Browse files
committed
fix(gw): blocked content produces http error 410
this is the minimum we need right now to make content blocking from ipfs/kubo#10161 return HTTP 410 on rule match
1 parent 07d1493 commit 182e86f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

gateway/errors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa
149149
code = http.StatusBadRequest
150150
case isErrNotFound(err):
151151
code = http.StatusNotFound
152+
case isErrContentBlocked(err):
153+
code = http.StatusGone
152154
case errors.Is(err, context.DeadlineExceeded):
153155
code = http.StatusGatewayTimeout
154156
}
@@ -202,3 +204,10 @@ func isErrNotFound(err error) bool {
202204
}
203205
}
204206
}
207+
208+
// isErrContentBlocked returns true for content filtering system errors
209+
func isErrContentBlocked(err error) bool {
210+
// TODO: we match error message to avoid pulling nopfs as a dependency
211+
// Ref. https://github.com/ipfs-shipyard/nopfs/blob/cde3b5ba964c13e977f4a95f3bd8ca7d7710fbda/status.go#L87-L89
212+
return strings.Contains(err.Error(), "blocked and cannot be provided")
213+
}

0 commit comments

Comments
 (0)