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
99ee2225
Unverified
Commit
99ee2225
authored
Feb 23, 2022
by
JJ Kasper
Committed by
GitHub
Feb 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normalize image optimizer error status codes (#34699)
parent
b3f2b388
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
image-optimizer.ts
packages/next/server/image-optimizer.ts
+7
-1
util.js
test/integration/image-optimizer/test/util.js
+21
-2
No files found.
packages/next/server/image-optimizer.ts
View file @
99ee2225
...
@@ -259,7 +259,13 @@ export class ImageError extends Error {
...
@@ -259,7 +259,13 @@ export class ImageError extends Error {
constructor
(
statusCode
:
number
,
message
:
string
)
{
constructor
(
statusCode
:
number
,
message
:
string
)
{
super
(
message
)
super
(
message
)
this
.
statusCode
=
statusCode
// ensure an error status is used > 400
if
(
statusCode
>=
400
)
{
this
.
statusCode
=
statusCode
}
else
{
this
.
statusCode
=
500
}
}
}
}
}
...
...
test/integration/image-optimizer/test/util.js
View file @
99ee2225
...
@@ -25,11 +25,17 @@ export async function serveSlowImage() {
...
@@ -25,11 +25,17 @@ export async function serveSlowImage() {
const
server
=
http
.
createServer
(
async
(
req
,
res
)
=>
{
const
server
=
http
.
createServer
(
async
(
req
,
res
)
=>
{
const
parsedUrl
=
new
URL
(
req
.
url
,
'http://localhost'
)
const
parsedUrl
=
new
URL
(
req
.
url
,
'http://localhost'
)
const
delay
=
Number
(
parsedUrl
.
searchParams
.
get
(
'delay'
))
||
500
const
delay
=
Number
(
parsedUrl
.
searchParams
.
get
(
'delay'
))
||
500
const
status
=
Number
(
parsedUrl
.
searchParams
.
get
(
'status'
))
||
200
console
.
log
(
'delay image for'
,
delay
)
console
.
log
(
'delay
ing
image for'
,
delay
)
await
waitFor
(
delay
)
await
waitFor
(
delay
)
res
.
statusCode
=
200
res
.
statusCode
=
status
if
(
status
===
308
)
{
res
.
end
(
'invalid status'
)
return
}
res
.
setHeader
(
'content-type'
,
'image/png'
)
res
.
setHeader
(
'content-type'
,
'image/png'
)
res
.
end
(
await
fs
.
readFile
(
join
(
__dirname
,
'../app/public/test.png'
)))
res
.
end
(
await
fs
.
readFile
(
join
(
__dirname
,
'../app/public/test.png'
)))
})
})
...
@@ -127,6 +133,19 @@ export function runTests(ctx) {
...
@@ -127,6 +133,19 @@ export function runTests(ctx) {
slowImageServer
.
stop
()
slowImageServer
.
stop
()
})
})
if
(
ctx
.
domains
.
includes
(
'localhost'
))
{
it
(
'should normalize invalid status codes'
,
async
()
=>
{
const
url
=
`http://localhost:
${
slowImageServer
.
port
}
/slow.png?delay=
${
1
}
&status=308`
const
query
=
{
url
,
w
:
ctx
.
w
,
q
:
39
}
const
opts
=
{
headers
:
{
accept
:
'image/webp'
},
redirect
:
'manual'
}
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/_next/image'
,
query
,
opts
)
expect
(
res
.
status
).
toBe
(
500
)
})
}
it
(
'should return home page'
,
async
()
=>
{
it
(
'should return home page'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/'
,
null
,
{})
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
'/'
,
null
,
{})
expect
(
await
res
.
text
()).
toMatch
(
/Image Optimizer Home/m
)
expect
(
await
res
.
text
()).
toMatch
(
/Image Optimizer Home/m
)
...
...
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