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
1c2249d0
Unverified
Commit
1c2249d0
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 (#77477)
Backports
https://github.com/vercel/next.js/pull/77474
to v13
parent
422223e9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
56 deletions
+0
-56
router-server.ts
packages/next/src/server/lib/router-server.ts
+0
-10
utils.ts
packages/next/src/server/lib/server-ipc/utils.ts
+0
-11
context.ts
packages/next/src/server/web/sandbox/context.ts
+0
-9
sandbox.ts
packages/next/src/server/web/sandbox/sandbox.ts
+0
-13
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 @
1c2249d0
...
...
@@ -134,16 +134,6 @@ export async function initialize(opts: {
renderServer
.
instance
=
require
(
'./render-server'
)
as
typeof
import
(
'./render-server'
)
const
randomBytes
=
new
Uint8Array
(
8
)
// handle node v16 not having global webcrypto
const
crypto
=
require
(
'crypto'
)
const
webcrypto
=
crypto
.
webcrypto
||
crypto
webcrypto
.
getRandomValues
(
randomBytes
)
const
middlewareSubrequestId
=
Buffer
.
from
(
randomBytes
).
toString
(
'hex'
)
;(
globalThis
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
=
middlewareSubrequestId
const
renderServerOpts
:
Parameters
<
RenderServer
[
'initialize'
]
>
[
0
]
=
{
port
:
opts
.
port
,
dir
:
opts
.
dir
,
...
...
packages/next/src/server/lib/server-ipc/utils.ts
View file @
1c2249d0
...
...
@@ -55,16 +55,5 @@ export const filterInternalHeaders = (
if
(
INTERNAL_HEADERS
.
includes
(
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 @
1c2249d0
...
...
@@ -310,15 +310,6 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`),
}
init
.
headers
=
new
Headers
(
init
.
headers
??
{})
const
prevs
=
init
.
headers
.
get
(
`x-middleware-subrequest`
)?.
split
(
':'
)
||
[]
const
value
=
prevs
.
concat
(
options
.
moduleName
).
join
(
':'
)
init
.
headers
.
set
(
'x-middleware-subrequest'
,
value
)
init
.
headers
.
set
(
'x-middleware-subrequest-id'
,
(
globalThis
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
)
if
(
!
init
.
headers
.
has
(
'user-agent'
))
{
init
.
headers
.
set
(
`user-agent`
,
`Next.js Middleware`
)
...
...
packages/next/src/server/web/sandbox/sandbox.ts
View file @
1c2249d0
...
...
@@ -74,19 +74,6 @@ export async function getRuntimeContext(params: {
export
const
run
=
withTaggedErrors
(
async
function
runWithTaggedErrors
(
params
)
{
const
runtime
=
await
getRuntimeContext
(
params
)
const
subreq
=
params
.
request
.
headers
[
`x-middleware-subrequest`
]
const
subrequests
=
typeof
subreq
===
'string'
?
subreq
.
split
(
':'
)
:
[]
if
(
subrequests
.
includes
(
params
.
name
))
{
return
{
waitUntil
:
Promise
.
resolve
(),
response
:
new
runtime
.
context
.
Response
(
null
,
{
headers
:
{
'x-middleware-next'
:
'1'
,
},
}),
}
}
const
edgeFunction
:
(
args
:
{
request
:
RequestData
})
=>
Promise
<
FetchEventResult
>
=
...
...
test/e2e/middleware-general/test/index.test.ts
View file @
1c2249d0
...
...
@@ -102,19 +102,6 @@ describe('Middleware Runtime', () => {
}
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 work with notFound: true correctly'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/ssr-page'
)
await
browser
.
eval
(
'window.beforeNav = 1'
)
...
...
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