Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7998b63a
Unverified
Commit
7998b63a
authored
Apr 30, 2022
by
Steven
Committed by
GitHub
Apr 30, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing `Content-Length` header from Image Optimization API (#36581)
Fixes #35514
parent
c838b5f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
image-optimizer.ts
packages/next/server/image-optimizer.ts
+1
-0
util.js
test/integration/image-optimizer/test/util.js
+11
-5
No files found.
packages/next/server/image-optimizer.ts
View file @
7998b63a
...
@@ -621,6 +621,7 @@ export function sendResponse(
...
@@ -621,6 +621,7 @@ export function sendResponse(
contentSecurityPolicy
contentSecurityPolicy
)
)
if
(
!
result
.
finished
)
{
if
(
!
result
.
finished
)
{
res
.
setHeader
(
'Content-Length'
,
Buffer
.
byteLength
(
buffer
))
res
.
end
(
buffer
)
res
.
end
(
buffer
)
}
}
}
}
...
...
test/integration/image-optimizer/test/util.js
View file @
7998b63a
...
@@ -70,10 +70,13 @@ export async function fsToJson(dir, output = {}) {
...
@@ -70,10 +70,13 @@ export async function fsToJson(dir, output = {}) {
return
output
return
output
}
}
export
async
function
expectWidth
(
res
,
w
)
{
export
async
function
expectWidth
(
res
,
w
,
{
expectAnimated
=
false
}
=
{}
)
{
const
buffer
=
await
res
.
buffer
()
const
buffer
=
await
res
.
buffer
()
const
d
=
sizeOf
(
buffer
)
const
d
=
sizeOf
(
buffer
)
expect
(
d
.
width
).
toBe
(
w
)
expect
(
d
.
width
).
toBe
(
w
)
const
lengthStr
=
res
.
headers
.
get
(
'Content-Length'
)
expect
(
lengthStr
).
toBe
(
Buffer
.
byteLength
(
buffer
).
toString
())
expect
(
isAnimated
(
buffer
)).
toBe
(
expectAnimated
)
}
}
export
const
cleanImagesDir
=
async
(
ctx
)
=>
{
export
const
cleanImagesDir
=
async
(
ctx
)
=>
{
...
@@ -170,7 +173,7 @@ export function runTests(ctx) {
...
@@ -170,7 +173,7 @@ export function runTests(ctx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`inline; filename="animated.gif"`
`inline; filename="animated.gif"`
)
)
expect
(
isAnimated
(
await
res
.
buffer
())).
toBe
(
true
)
await
expectWidth
(
res
,
50
,
{
expectAnimated
:
true
}
)
})
})
it
(
'should maintain animated png'
,
async
()
=>
{
it
(
'should maintain animated png'
,
async
()
=>
{
...
@@ -186,7 +189,7 @@ export function runTests(ctx) {
...
@@ -186,7 +189,7 @@ export function runTests(ctx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`inline; filename="animated.png"`
`inline; filename="animated.png"`
)
)
expect
(
isAnimated
(
await
res
.
buffer
())).
toBe
(
true
)
await
expectWidth
(
res
,
100
,
{
expectAnimated
:
true
}
)
})
})
it
(
'should maintain animated png 2'
,
async
()
=>
{
it
(
'should maintain animated png 2'
,
async
()
=>
{
...
@@ -202,7 +205,7 @@ export function runTests(ctx) {
...
@@ -202,7 +205,7 @@ export function runTests(ctx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`inline; filename="animated2.png"`
`inline; filename="animated2.png"`
)
)
expect
(
isAnimated
(
await
res
.
buffer
())).
toBe
(
true
)
await
expectWidth
(
res
,
1105
,
{
expectAnimated
:
true
}
)
})
})
it
(
'should maintain animated webp'
,
async
()
=>
{
it
(
'should maintain animated webp'
,
async
()
=>
{
...
@@ -218,7 +221,7 @@ export function runTests(ctx) {
...
@@ -218,7 +221,7 @@ export function runTests(ctx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`inline; filename="animated.webp"`
`inline; filename="animated.webp"`
)
)
expect
(
isAnimated
(
await
res
.
buffer
())).
toBe
(
true
)
await
expectWidth
(
res
,
400
,
{
expectAnimated
:
true
}
)
})
})
if
(
ctx
.
dangerouslyAllowSVG
)
{
if
(
ctx
.
dangerouslyAllowSVG
)
{
...
@@ -227,6 +230,7 @@ export function runTests(ctx) {
...
@@ -227,6 +230,7 @@ export function runTests(ctx) {
const
opts
=
{
headers
:
{
accept
:
'image/webp'
}
}
const
opts
=
{
headers
:
{
accept
:
'image/webp'
}
}
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/_next/image'
,
query
,
opts
)
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/_next/image'
,
query
,
opts
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
headers
.
get
(
'Content-Length'
)).
toBe
(
'603'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toContain
(
'image/svg+xml'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toContain
(
'image/svg+xml'
)
expect
(
res
.
headers
.
get
(
'Cache-Control'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Cache-Control'
)).
toBe
(
`public, max-age=0, must-revalidate`
`public, max-age=0, must-revalidate`
...
@@ -329,6 +333,7 @@ export function runTests(ctx) {
...
@@ -329,6 +333,7 @@ export function runTests(ctx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`inline; filename="test.jpeg"`
`inline; filename="test.jpeg"`
)
)
await
expectWidth
(
res
,
ctx
.
w
)
})
})
if
(
!
ctx
.
isOutdatedSharp
)
{
if
(
!
ctx
.
isOutdatedSharp
)
{
...
@@ -348,6 +353,7 @@ export function runTests(ctx) {
...
@@ -348,6 +353,7 @@ export function runTests(ctx) {
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
expect
(
res
.
headers
.
get
(
'Content-Disposition'
)).
toBe
(
`inline; filename="test.jpeg"`
`inline; filename="test.jpeg"`
)
)
await
expectWidth
(
res
,
ctx
.
w
)
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment