Skip to content

Commit

Permalink
refactor(asset-proxy): build a new Response to modify it since, depen…
Browse files Browse the repository at this point in the history
…ding on the response, the set-cookie is immutable and deleting it throws error
  • Loading branch information
hugotiburtino committed Oct 30, 2024
1 parent 59888d7 commit 681d4cd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/asset-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ export async function assetProxy(

const assetUrl = new Url(urlParam)

// Maybe add other validations?
if (response.ok) {
response.headers.delete('Set-Cookie')
const originalResponse = await fetch(assetUrl, { cf: { cacheTtl: 24 * 60 * 60 } })

if (originalResponse.ok) {
const response = new Response(originalResponse.body, originalResponse)
response.headers.delete('set-cookie')
return response
} else {
const sentry = sentryFactory.createReporter('asset-proxy')
sentry.setContext(
'response',
responseToContext({ response, text: await response.text() }),
responseToContext({ response: originalResponse, text: await originalResponse.text() }),
)
sentry.captureMessage(`Illegal response of ${assetUrl}`, 'warning')
sentry.captureMessage(`Illegal response of ${assetUrl.toString()}`, 'warning')
}

return null
Expand Down

0 comments on commit 681d4cd

Please sign in to comment.