feat(gateway): introduce typed errors for blocked content#855
feat(gateway): introduce typed errors for blocked content#855PsychoPunkSage wants to merge 2 commits intoipfs:mainfrom PsychoPunkSage:issue-591
Conversation
Signed-off-by: Abhinav Prakash <abhinav.prakash319@gmail.com>
Signed-off-by: Abhinav Prakash <abhinav.prakash319@gmail.com>
There was a problem hiding this comment.
There is bit more to do here, this PR in current form does not solve #591 – see comment inline.
@PsychoPunkSage Mind opening a companion PR against https://github.com/ipfs/kubo that uses boxo from this PR? We have content blocking tests there in https://github.com/ipfs/kubo/blob/master/test/cli/content_blocking_test.go that need to pass before we are comfortable merging this.
Also cc'ing @MichaelMure for feedback from his end: does this look like useful direction?
| // Will default to Error:451 if no status code is provided | ||
| if statusCode != http.StatusGone && statusCode != http.StatusUnavailableForLegalReasons { | ||
| statusCode = http.StatusUnavailableForLegalReasons // 451 by default | ||
| } |
There was a problem hiding this comment.
nit: legal one should not be the default, switch to 410
| 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") | ||
| var blocked *ErrorContentBlocked | ||
| return errors.As(err, &blocked) |
There was a problem hiding this comment.
Right now nothing will return ErrorContentBlocked type, so isErrContentBlocked will always return false and break content blocking response code in projects that use boxo/gateway, like Kubo.
What is the plan for making this work?
We don't want to depend on https://github.com/ipfs-shipyard/nopfs as noted in the comment here. Perhaps we want to keep the string.Contains and check it in addition to the type check here?
|
Triage notes:
|
Previously, blocked content detection relied on string matching which is fragile and implementation-specific. This PR:
ErrorContentBlockedtype to properly handle blocked content errorsRelated: closes #591