-
Notifications
You must be signed in to change notification settings - Fork 117
feat(gateway): introduce typed errors for blocked content #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Abhinav Prakash <[email protected]>
Signed-off-by: Abhinav Prakash <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: legal one should not be the default, switch to 410
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Triage notes:
|
Previously, blocked content detection relied on string matching which is fragile and implementation-specific. This PR:
ErrorContentBlocked
type to properly handle blocked content errorsRelated: closes #591