Skip to content

Commit

Permalink
fix(gw): blocked content produces http error 410
Browse files Browse the repository at this point in the history
this is the minimum we need right now to make
content blocking from
ipfs/kubo#10161
return HTTP 410 on rule match
  • Loading branch information
lidel committed Oct 28, 2023
1 parent 07d1493 commit 72da286
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gateway/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 153 in gateway/errors.go

View check run for this annotation

Codecov / codecov/patch

gateway/errors.go#L152-L153

Added lines #L152 - L153 were not covered by tests
case errors.Is(err, context.DeadlineExceeded):
code = http.StatusGatewayTimeout
}
Expand Down Expand Up @@ -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") {

Check failure on line 212 in gateway/errors.go

View workflow job for this annotation

GitHub Actions / go-check / All

should use 'return strings.Contains(err.Error(), "blocked and cannot be provided")' instead of 'if strings.Contains(err.Error(), "blocked and cannot be provided") { return true }; return false' (S1008)
return true
}

Check warning on line 214 in gateway/errors.go

View check run for this annotation

Codecov / codecov/patch

gateway/errors.go#L213-L214

Added lines #L213 - L214 were not covered by tests
return false
}

0 comments on commit 72da286

Please sign in to comment.