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
8a511d6a
Unverified
Commit
8a511d6a
authored
Mar 24, 2025
by
JJ Kasper
Committed by
GitHub
Mar 24, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Match subrequest handling for edge and node (#77476)
Backports
https://github.com/vercel/next.js/pull/77474
to v14
parent
d36a1f3c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
0 additions
and
109 deletions
+0
-109
router-server.ts
packages/next/src/server/lib/router-server.ts
+0
-6
utils.ts
packages/next/src/server/lib/server-ipc/utils.ts
+0
-11
context.ts
packages/next/src/server/web/sandbox/context.ts
+0
-21
sandbox.ts
packages/next/src/server/web/sandbox/sandbox.ts
+0
-19
app-routes-subrequests.test.ts
...dir/app-routes-subrequests/app-routes-subrequests.test.ts
+0
-18
route.ts
test/e2e/app-dir/app-routes-subrequests/app/route.ts
+0
-11
next.config.js
test/e2e/app-dir/app-routes-subrequests/next.config.js
+0
-10
index.test.ts
test/e2e/middleware-general/test/index.test.ts
+0
-13
No files found.
packages/next/src/server/lib/router-server.ts
View file @
8a511d6a
...
@@ -149,12 +149,6 @@ export async function initialize(opts: {
...
@@ -149,12 +149,6 @@ export async function initialize(opts: {
renderServer
.
instance
=
renderServer
.
instance
=
require
(
'./render-server'
)
as
typeof
import
(
'./render-server'
)
require
(
'./render-server'
)
as
typeof
import
(
'./render-server'
)
const
randomBytes
=
new
Uint8Array
(
8
)
crypto
.
getRandomValues
(
randomBytes
)
const
middlewareSubrequestId
=
Buffer
.
from
(
randomBytes
).
toString
(
'hex'
)
;(
globalThis
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
=
middlewareSubrequestId
const
requestHandlerImpl
:
WorkerRequestHandler
=
async
(
req
,
res
)
=>
{
const
requestHandlerImpl
:
WorkerRequestHandler
=
async
(
req
,
res
)
=>
{
// internal headers should not be honored by the request handler
// internal headers should not be honored by the request handler
if
(
!
process
.
env
.
NEXT_PRIVATE_TEST_HEADERS
)
{
if
(
!
process
.
env
.
NEXT_PRIVATE_TEST_HEADERS
)
{
...
...
packages/next/src/server/lib/server-ipc/utils.ts
View file @
8a511d6a
...
@@ -57,16 +57,5 @@ export const filterInternalHeaders = (
...
@@ -57,16 +57,5 @@ export const filterInternalHeaders = (
if
(
INTERNAL_HEADERS
.
includes
(
header
))
{
if
(
INTERNAL_HEADERS
.
includes
(
header
))
{
delete
headers
[
header
]
delete
headers
[
header
]
}
}
// If this request didn't origin from this session we filter
// out the "x-middleware-subrequest" header so we don't skip
// middleware incorrectly
if
(
header
===
'x-middleware-subrequest'
&&
headers
[
'x-middleware-subrequest-id'
]
!==
(
globalThis
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
)
{
delete
headers
[
'x-middleware-subrequest'
]
}
}
}
}
}
packages/next/src/server/web/sandbox/context.ts
View file @
8a511d6a
...
@@ -354,27 +354,6 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`),
...
@@ -354,27 +354,6 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`),
init
.
headers
=
new
Headers
(
init
.
headers
??
{})
init
.
headers
=
new
Headers
(
init
.
headers
??
{})
// Forward subrequest header from incoming request to outgoing request
const
store
=
requestStore
.
getStore
()
if
(
store
?.
headers
.
has
(
'x-middleware-subrequest'
)
&&
!
init
.
headers
.
has
(
'x-middleware-subrequest'
)
)
{
init
.
headers
.
set
(
'x-middleware-subrequest'
,
store
.
headers
.
get
(
'x-middleware-subrequest'
)
??
''
)
}
init
.
headers
.
set
(
'x-middleware-subrequest-id'
,
(
globalThis
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
)
const
prevs
=
init
.
headers
.
get
(
`x-middleware-subrequest`
)?.
split
(
':'
)
||
[]
const
value
=
prevs
.
concat
(
options
.
moduleName
).
join
(
':'
)
init
.
headers
.
set
(
'x-middleware-subrequest'
,
value
)
if
(
!
init
.
headers
.
has
(
'user-agent'
))
{
if
(
!
init
.
headers
.
has
(
'user-agent'
))
{
init
.
headers
.
set
(
`user-agent`
,
`Next.js Middleware`
)
init
.
headers
.
set
(
`user-agent`
,
`Next.js Middleware`
)
}
}
...
...
packages/next/src/server/web/sandbox/sandbox.ts
View file @
8a511d6a
...
@@ -83,25 +83,6 @@ export async function getRuntimeContext(params: {
...
@@ -83,25 +83,6 @@ export async function getRuntimeContext(params: {
export
const
run
=
withTaggedErrors
(
async
function
runWithTaggedErrors
(
params
)
{
export
const
run
=
withTaggedErrors
(
async
function
runWithTaggedErrors
(
params
)
{
const
runtime
=
await
getRuntimeContext
(
params
)
const
runtime
=
await
getRuntimeContext
(
params
)
const
subreq
=
params
.
request
.
headers
[
`x-middleware-subrequest`
]
const
subrequests
=
typeof
subreq
===
'string'
?
subreq
.
split
(
':'
)
:
[]
const
MAX_RECURSION_DEPTH
=
5
const
depth
=
subrequests
.
reduce
(
(
acc
,
curr
)
=>
(
curr
===
params
.
name
?
acc
+
1
:
acc
),
0
)
if
(
depth
>=
MAX_RECURSION_DEPTH
)
{
return
{
waitUntil
:
Promise
.
resolve
(),
response
:
new
runtime
.
context
.
Response
(
null
,
{
headers
:
{
'x-middleware-next'
:
'1'
,
},
}),
}
}
const
edgeFunction
:
(
args
:
{
const
edgeFunction
:
(
args
:
{
request
:
RequestData
request
:
RequestData
...
...
test/e2e/app-dir/app-routes-subrequests/app-routes-subrequests.test.ts
deleted
100644 → 0
View file @
d36a1f3c
import
{
createNextDescribe
}
from
'e2e-utils'
const
bathPath
=
process
.
env
.
BASE_PATH
??
''
createNextDescribe
(
'app-routes-subrequests'
,
{
files
:
__dirname
,
skipDeployment
:
true
,
},
({
next
})
=>
{
it
(
'shortcuts after 5 subrequests'
,
async
()
=>
{
expect
(
JSON
.
parse
(
await
next
.
render
(
bathPath
+
'/'
))).
toEqual
({
count
:
5
,
})
})
}
)
test/e2e/app-dir/app-routes-subrequests/app/route.ts
deleted
100644 → 0
View file @
d36a1f3c
import
{
NextRequest
,
NextResponse
}
from
'next/server'
export
const
runtime
=
'edge'
let
count
=
0
export
const
GET
=
async
(
req
:
NextRequest
)
=>
{
await
fetch
(
req
.
nextUrl
)
count
++
return
NextResponse
.
json
({
count
})
}
test/e2e/app-dir/app-routes-subrequests/next.config.js
deleted
100644 → 0
View file @
d36a1f3c
/**
* @type {import('next').NextConfig}
*/
const
config
=
{
typescript
:
{
ignoreBuildErrors
:
true
,
},
}
module
.
exports
=
config
test/e2e/middleware-general/test/index.test.ts
View file @
8a511d6a
...
@@ -102,19 +102,6 @@ describe('Middleware Runtime', () => {
...
@@ -102,19 +102,6 @@ describe('Middleware Runtime', () => {
}
}
function
runTests
({
i18n
}:
{
i18n
?:
boolean
})
{
function
runTests
({
i18n
}:
{
i18n
?:
boolean
})
{
it
(
'should filter request header properly'
,
async
()
=>
{
const
res
=
await
next
.
fetch
(
'/redirect-to-somewhere'
,
{
headers
:
{
'x-middleware-subrequest'
:
'middleware:middleware:middleware:middleware:middleware'
,
},
redirect
:
'manual'
,
})
expect
(
res
.
status
).
toBe
(
307
)
expect
(
res
.
headers
.
get
(
'location'
)).
toContain
(
'/somewhere'
)
})
it
(
'should handle 404 on fallback: false route correctly'
,
async
()
=>
{
it
(
'should handle 404 on fallback: false route correctly'
,
async
()
=>
{
const
res
=
await
next
.
fetch
(
'/ssg-fallback-false/first'
)
const
res
=
await
next
.
fetch
(
'/ssg-fallback-false/first'
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
status
).
toBe
(
200
)
...
...
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