Unverified Commit 3f07d5ea authored by Steven's avatar Steven Committed by GitHub

[16.x] fix(next/image): preserve image response after optimization (#96733)

Co-authored-by: 's avatarvercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
parent b20f297a
...@@ -99,6 +99,7 @@ export function getSharp( ...@@ -99,6 +99,7 @@ export function getSharp(
'VipsForeignLoadJpeg', 'VipsForeignLoadJpeg',
'VipsForeignLoadNsgif', 'VipsForeignLoadNsgif',
'VipsForeignLoadPng', 'VipsForeignLoadPng',
'VipsForeignLoadSvg',
'VipsForeignLoadTiff', 'VipsForeignLoadTiff',
'VipsForeignLoadWebp', 'VipsForeignLoadWebp',
], ],
......
const pixel = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+X8mN6QAAAABJRU5ErkJggg==',
'base64'
)
export async function GET() {
return new Response(pixel, {
headers: {
'Content-Type': 'image/png',
},
})
}
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup } from 'e2e-utils'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils' import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import { randomUUID } from 'crypto'
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
...@@ -32,12 +33,27 @@ describe('og-api', () => { ...@@ -32,12 +33,27 @@ describe('og-api', () => {
expect(body.size).toBeGreaterThan(0) expect(body.size).toBeGreaterThan(0)
}) })
it('should work in app route in node runtime', async () => { it('should work in app route in node runtime after image optimization', async () => {
const res = await fetchViaHTTP(next.url, '/og-node') const before = await fetchViaHTTP(next.url, '/og-node')
expect(res.status).toBe(200) expect(before.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png') expect(before.headers.get('content-type')).toContain('image/png')
const body = await res.blob() expect((await before.blob()).size).toBeGreaterThan(0)
expect(body.size).toBeGreaterThan(0)
const imageUrl = encodeURIComponent(`/pixel/${randomUUID()}`)
const optimized = await fetchViaHTTP(
next.url,
`/_next/image?url=${imageUrl}&w=640&q=75`
)
expect(optimized.status).toBe(200)
expect(
optimized.headers.get('x-vercel-cache') ||
optimized.headers.get('x-nextjs-cache')
).toBe('MISS')
const after = await fetchViaHTTP(next.url, '/og-node')
expect(after.status).toBe(200)
expect(after.headers.get('content-type')).toContain('image/png')
expect((await after.blob()).size).toBeGreaterThan(0)
}) })
it('should work in middleware', async () => { it('should work in middleware', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment