Skip to content

Commit 63c7985

Browse files
committed
Match subrequest handling for edge and node
1 parent fedcd25 commit 63c7985

File tree

4 files changed

+0
-51
lines changed

4 files changed

+0
-51
lines changed

packages/next/server/next-server.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import type { NextConfig } from './config-shared'
2727
import type { DynamicRoutes, PageChecker } from './router'
2828

2929
import fs from 'fs'
30-
import crypto from 'crypto'
3130
import { join, relative, resolve, sep } from 'path'
3231
import { IncomingMessage, ServerResponse } from 'http'
3332
import { addRequestMeta, getRequestMeta } from './request-meta'
@@ -248,11 +247,6 @@ export default class NextNodeServer extends BaseServer {
248247
)
249248
}
250249

251-
const randomBytes = crypto.randomBytes(8)
252-
const middlewareSubrequestId = randomBytes.toString('hex')
253-
;(global as any)[Symbol.for('@next/middleware-subrequest-id')] =
254-
middlewareSubrequestId
255-
256250
if (!options.dev) {
257251
// pre-warm _document and _app as these will be
258252
// needed for most requests

packages/next/server/web/sandbox/context.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,6 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`),
218218
}
219219

220220
init.headers = new Headers(init.headers ?? {})
221-
const prevs =
222-
init.headers.get(`x-middleware-subrequest`)?.split(':') || []
223-
const value = prevs.concat(options.moduleName).join(':')
224-
225-
init.headers.set('x-middleware-subrequest', value)
226-
init.headers.set(
227-
'x-middleware-subrequest-id',
228-
(global as any)[Symbol.for('@next/middleware-subrequest-id')]
229-
)
230221

231222
if (!init.headers.has('user-agent')) {
232223
init.headers.set(`user-agent`, `Next.js Middleware`)

packages/next/server/web/sandbox/sandbox.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,6 @@ export const getRuntimeContext = async (params: {
7070

7171
export const run = withTaggedErrors(async (params) => {
7272
const runtime = await getRuntimeContext(params)
73-
const subreq = params.request.headers[`x-middleware-subrequest`]
74-
const subrequests = typeof subreq === 'string' ? subreq.split(':') : []
75-
if (
76-
// require the subrequest-id be valid to skip
77-
params.request.headers['x-middleware-subrequest-id'] ===
78-
(global as any)[Symbol.for('@next/middleware-subrequest-id')] &&
79-
subrequests.includes(params.name)
80-
) {
81-
return {
82-
waitUntil: Promise.resolve(),
83-
response: new runtime.context.Response(null, {
84-
headers: {
85-
'x-middleware-next': '1',
86-
},
87-
}),
88-
}
89-
}
90-
9173
const edgeFunction: (args: {
9274
request: RequestData
9375
}) => Promise<FetchEventResult> =

test/e2e/middleware-general/test/index.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,6 @@ describe('Middleware Runtime', () => {
7171
}
7272

7373
function runTests({ i18n }: { i18n?: boolean }) {
74-
it('should filter request header properly', async () => {
75-
const res = await fetchViaHTTP(
76-
next.url,
77-
'/redirect-to-somewhere',
78-
{},
79-
{
80-
headers: {
81-
'x-middleware-subrequest':
82-
'middleware:middleware:middleware:middleware:middleware',
83-
},
84-
redirect: 'manual',
85-
}
86-
)
87-
88-
expect(res.status).toBe(307)
89-
expect(res.headers.get('location')).toContain('/somewhere')
90-
})
91-
9274
if ((global as any).isNextDev) {
9375
it('refreshes the page when middleware changes ', async () => {
9476
const browser = await webdriver(next.url, `/about`)

0 commit comments

Comments
 (0)