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
63c79857
Commit
63c79857
authored
Mar 24, 2025
by
JJ Kasper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Match subrequest handling for edge and node
parent
fedcd25f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
51 deletions
+0
-51
next-server.ts
packages/next/server/next-server.ts
+0
-6
context.ts
packages/next/server/web/sandbox/context.ts
+0
-9
sandbox.ts
packages/next/server/web/sandbox/sandbox.ts
+0
-18
index.test.ts
test/e2e/middleware-general/test/index.test.ts
+0
-18
No files found.
packages/next/server/next-server.ts
View file @
63c79857
...
...
@@ -27,7 +27,6 @@ import type { NextConfig } from './config-shared'
import
type
{
DynamicRoutes
,
PageChecker
}
from
'./router'
import
fs
from
'fs'
import
crypto
from
'crypto'
import
{
join
,
relative
,
resolve
,
sep
}
from
'path'
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
{
addRequestMeta
,
getRequestMeta
}
from
'./request-meta'
...
...
@@ -248,11 +247,6 @@ export default class NextNodeServer extends BaseServer {
)
}
const
randomBytes
=
crypto
.
randomBytes
(
8
)
const
middlewareSubrequestId
=
randomBytes
.
toString
(
'hex'
)
;(
global
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
=
middlewareSubrequestId
if
(
!
options
.
dev
)
{
// pre-warm _document and _app as these will be
// needed for most requests
...
...
packages/next/server/web/sandbox/context.ts
View file @
63c79857
...
...
@@ -218,15 +218,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'
,
(
global
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
)
if
(
!
init
.
headers
.
has
(
'user-agent'
))
{
init
.
headers
.
set
(
`user-agent`
,
`Next.js Middleware`
)
...
...
packages/next/server/web/sandbox/sandbox.ts
View file @
63c79857
...
...
@@ -70,24 +70,6 @@ export const getRuntimeContext = async (params: {
export
const
run
=
withTaggedErrors
(
async
(
params
)
=>
{
const
runtime
=
await
getRuntimeContext
(
params
)
const
subreq
=
params
.
request
.
headers
[
`x-middleware-subrequest`
]
const
subrequests
=
typeof
subreq
===
'string'
?
subreq
.
split
(
':'
)
:
[]
if
(
// require the subrequest-id be valid to skip
params
.
request
.
headers
[
'x-middleware-subrequest-id'
]
===
(
global
as
any
)[
Symbol
.
for
(
'@next/middleware-subrequest-id'
)]
&&
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 @
63c79857
...
...
@@ -71,24 +71,6 @@ describe('Middleware Runtime', () => {
}
function
runTests
({
i18n
}:
{
i18n
?:
boolean
})
{
it
(
'should filter request header properly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/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'
)
})
if
((
global
as
any
).
isNextDev
)
{
it
(
'refreshes the page when middleware changes '
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
`/about`
)
...
...
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