Skip to content

Commit

Permalink
fix: public gateways might give us invalid etags (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Sep 27, 2022
1 parent 09f9591 commit 0717443
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/edge-gateway/src/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export async function gatewayGet (request, env, ctx) {
const resourceCid = getCidFromEtag(winnerGwResponse.headers.get('etag') || '')
if (winnerGwResponse && pathname !== '/' && resourceCid) {
const cidResourceDenylistResponse = await env.CID_VERIFIER.fetch(`${env.CID_VERIFIER_URL}/denylist?cid=${resourceCid}`)
if (cidResourceDenylistResponse.status !== 204) {
// Ignore if CID received from gateway in etag header is invalid by any reason
if (cidResourceDenylistResponse.status !== 204 && cidResourceDenylistResponse.status !== 400) {
return cidResourceDenylistResponse
}
}
Expand Down Expand Up @@ -350,8 +351,8 @@ function getCidFromEtag (etag) {
let resourceCid = decodeURIComponent(etag)

// Handle weak etag
resourceCid.replace('W/', '')
resourceCid.replaceAll('"', '')
resourceCid = resourceCid.replace('W/', '')
resourceCid = resourceCid.replaceAll('"', '')

// Handle directory index generated
if (etag.includes('DirIndex')) {
Expand Down

0 comments on commit 0717443

Please sign in to comment.