mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
fix(next/image): fix image-optimizer.ts headers (#82114)
The headers were forwarded to the serverless function for "internal" images but not "external" images. This changes the behavior to be the same for both such that neither receive headers.
This commit is contained in:
@@ -634,7 +634,6 @@ export async function fetchInternalImage(
|
||||
const mocked = createRequestResponseMocks({
|
||||
url: href,
|
||||
method: _req.method || 'GET',
|
||||
headers: _req.headers,
|
||||
socket: _req.socket,
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
const pixel =
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg=='
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.headers['cookie']) {
|
||||
res.setHeader('content-type', 'image/png')
|
||||
res.end(Buffer.from(pixel, 'base64'))
|
||||
} else {
|
||||
res.status(401).end('cookie was not found')
|
||||
}
|
||||
}
|
||||
@@ -308,6 +308,13 @@ export function runTests(ctx: RunTestsCtx) {
|
||||
expect(ctx.nextOutput).toContain(animatedWarnText)
|
||||
})
|
||||
|
||||
it('should not forward cookie header', async () => {
|
||||
const query = { w: ctx.w, q: 30, url: '/api/conditional-cookie' }
|
||||
const opts = { headers: { accept: 'image/webp', cookie: '1' } }
|
||||
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
|
||||
if (ctx.nextConfigImages?.dangerouslyAllowSVG) {
|
||||
it('should maintain vector svg', async () => {
|
||||
const query = { w: ctx.w, q: 90, url: '/test.svg' }
|
||||
|
||||
Reference in New Issue
Block a user