Skip to content

Commit

Permalink
fix(asset-proxy): be sure all headers are passed to the final endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hugotiburtino committed Nov 20, 2024
1 parent 3d47221 commit 70a235b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 12 additions & 5 deletions __tests__/asset-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ test('request to https://asset-proxy.serlo.org/image?url=* gets asset from url q

test('request to asset-proxy works also in case of other encodings', async () => {
const env = currentTestEnvironment()
const response = await env.fetch({
subdomain: 'asset-proxy',
pathname:
'/image?url=https://upload.wikimedia.org/wikipedia/commons/8/8b/Sinus_mit_y.svg',
})
const response = await env.fetch(
{
subdomain: 'asset-proxy',
pathname:
'/image?url=https://upload.wikimedia.org/wikipedia/commons/8/8b/Sinus_mit_y.svg',
},
{
headers: {
'Accept-Encoding': '*',
},
},
)
expect(response.status).toBe(200)
expect(response.headers.get('content-type')).toBe('image/svg+xml')
expect(response.headers.get('Set-Cookie')).toBeNull()
Expand Down
10 changes: 6 additions & 4 deletions src/asset-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export async function assetProxy(request: Request): Promise<Response | null> {
return getPlaceholder()
}

const originalResponse = await fetch(assetUrl, {
cf: { cacheTtl: 24 * 60 * 60 * 30 },
headers: { 'Accept-Encoding': '*' },
})
const originalResponse = await fetch(
new Request(assetUrl.toString(), request),
{
cf: { cacheTtl: 24 * 60 * 60 * 30 },
},
)

if (originalResponse.ok && isImageResponse(originalResponse)) {
const response = new Response(originalResponse.body, originalResponse)
Expand Down

0 comments on commit 70a235b

Please sign in to comment.