diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 5f89cd1a3fdd5..59ffdba6ebaa7 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -26,20 +26,20 @@ jobs: isRelease: ${{ github.event_name != 'workflow_dispatch' && steps.check-release.outputs.IS_RELEASE }} steps: - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_LTS_VERSION }} check-latest: true - run: corepack enable - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 - id: get-store-path run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 timeout-minutes: 5 id: cache-pnpm-store with: @@ -62,7 +62,7 @@ jobs: echo "IS_RELEASE=false" >> $GITHUB_OUTPUT fi - - uses: actions/cache@v3 + - uses: actions/cache@v4 timeout-minutes: 5 id: cache-build with: @@ -86,8 +86,8 @@ jobs: target: 'x86_64-apple-darwin' build: | - npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" && corepack enable - turbo run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target x86_64-apple-darwin --release + npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" && corepack enable + pnpm dlx turbo@${TURBO_VERSION} run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target x86_64-apple-darwin --release strip -x packages/next-swc/native/next-swc.*.node - host: @@ -101,8 +101,8 @@ jobs: export CXX=$(xcrun -f clang++); SYSROOT=$(xcrun --sdk macosx --show-sdk-path); export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT"; - npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" && corepack enable - turbo run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target aarch64-apple-darwin + npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" && corepack enable + pnpm dlx turbo@${TURBO_VERSION} run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target aarch64-apple-darwin strip -x packages/next-swc/native/next-swc.*.node - host: @@ -112,8 +112,8 @@ jobs: build: | corepack enable - npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" - turbo run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target x86_64-pc-windows-msvc + npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" + pnpm dlx turbo@${TURBO_VERSION} run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target x86_64-pc-windows-msvc target: 'x86_64-pc-windows-msvc' - host: @@ -123,8 +123,8 @@ jobs: build: | corepack enable - npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" - turbo run build-native-no-plugin -vvv --remote-cache-timeout 90 --summarize -- --release --target i686-pc-windows-msvc + npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" + pnpm dlx turbo@${TURBO_VERSION} run build-native-no-plugin -vvv --remote-cache-timeout 90 --summarize -- --release --target i686-pc-windows-msvc target: 'i686-pc-windows-msvc' - host: @@ -135,8 +135,8 @@ jobs: target: 'aarch64-pc-windows-msvc' build: | corepack enable - npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" - turbo run build-native-no-plugin-woa-release -vvv --remote-cache-timeout 90 --summarize -- --target aarch64-pc-windows-msvc + npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" + pnpm dlx turbo@${TURBO_VERSION} run build-native-no-plugin-woa-release -vvv --remote-cache-timeout 90 --summarize -- --target aarch64-pc-windows-msvc - host: - 'self-hosted' @@ -246,10 +246,10 @@ jobs: if: ${{ matrix.settings.host == 'macos-latest' }} # we use checkout here instead of the build cache since # it can fail to restore in different OS' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 if: ${{ !matrix.settings.docker }} with: node-version: ${{ env.NODE_LTS_VERSION }} @@ -294,7 +294,7 @@ jobs: - name: cache build if: ${{ matrix.settings.docker && steps.build-exists.outputs.BUILD_EXISTS == 'no' }} - run: pnpm turbo run cache-build-native --force -- ${{ matrix.settings.target }} + run: pnpm dlx turbo@${TURBO_VERSION} run cache-build-native --force -- ${{ matrix.settings.target }} - name: 'Build' run: ${{ matrix.settings.build }} @@ -324,22 +324,22 @@ jobs: - name: Upload turbopack bytesize artifact if: ${{ steps.check-did-build.outputs.DID_BUILD == 'yup' }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: turbopack-bytesize path: turbopack-bin-size/* - name: Upload swc artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: next-swc-binaries path: packages/next-swc/native/next-swc.*.node - - name: Upload turbo summary artifact - uses: actions/upload-artifact@v3 - with: - name: turbo run summary - path: .turbo/runs + # - name: Upload turbo summary artifact + # uses: actions/upload-artifact@v4 + # with: + # name: turbo run summary + # path: .turbo/runs build-wasm: strategy: @@ -353,10 +353,10 @@ jobs: - 'metal' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_LTS_VERSION }} check-latest: true @@ -376,19 +376,19 @@ jobs: run: node scripts/normalize-version-bump.js - name: Build - run: turbo run build-wasm -vvv --remote-cache-timeout 90 --summarize -- --target ${{ matrix.target }} --features tracing/release_max_level_info + run: pnpm dlx turbo@${TURBO_VERSION} run build-wasm -vvv --remote-cache-timeout 90 --summarize -- --target ${{ matrix.target }} --features tracing/release_max_level_info - name: Add target to folder name run: '[[ -d "packages/next-swc/crates/wasm/pkg" ]] && mv packages/next-swc/crates/wasm/pkg packages/next-swc/crates/wasm/pkg-${{ matrix.target }} || ls packages/next-swc/crates/wasm' - name: Upload turbo summary artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: turbo run summary + name: pnpm dlx turbo@${TURBO_VERSION} run summary path: .turbo/runs - name: Upload swc artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wasm-binaries path: packages/next-swc/crates/wasm/pkg-* @@ -408,7 +408,7 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }} steps: - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_LTS_VERSION }} check-latest: true @@ -418,19 +418,19 @@ jobs: - name: tune linux network run: sudo ethtool -K eth0 tx off rx off - - uses: actions/cache@v3 + - uses: actions/cache@v4 timeout-minutes: 5 id: restore-build with: path: ./* key: ${{ github.sha }}-${{ github.run_number }} - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: next-swc-binaries path: packages/next-swc/native - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: wasm-binaries path: packages/next-swc/crates/wasm @@ -445,7 +445,7 @@ jobs: runs-on: ubuntu-latest needs: [build] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 - name: Install Vercel CLI @@ -473,11 +473,11 @@ jobs: timeout-minutes: 25 needs: [publishRelease] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: next-swc-binaries path: packages/next-swc/native @@ -498,7 +498,7 @@ jobs: DATADOG_API_KEY: ${{ secrets.DATA_DOG_API_KEY }} steps: - name: Collect bytesize traces - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: turbopack-bytesize path: turbopack-bin-size diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index af6341734cb09..24fb913312931 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -26,6 +26,7 @@ env: DD_ENV: 'ci' TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }} NEXT_TEST_JOB: 1 + COREPACK_ENABLE_STRICT: 0 jobs: build-native: @@ -54,8 +55,8 @@ jobs: validate-docs-links: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: 18 - run: corepack enable @@ -84,7 +85,7 @@ jobs: needsRust: 'yes' skipInstallBuild: 'yes' skipNativeBuild: 'yes' - afterBuild: turbo run test-cargo-unit + afterBuild: pnpm dlx turbo@${TURBO_VERSION} run test-cargo-unit mold: 'yes' secrets: inherit @@ -98,7 +99,7 @@ jobs: needsNextest: 'yes' needsRust: 'yes' skipNativeBuild: 'yes' - afterBuild: xvfb-run turbo run test-cargo-integration + afterBuild: xvfb-run pnpm dlx turbo@${TURBO_VERSION} run test-cargo-integration test-cargo-bench: name: test cargo benchmarks @@ -110,7 +111,7 @@ jobs: skipForRelease: 'yes' needsRust: 'yes' skipNativeBuild: 'yes' - afterBuild: xvfb-run turbo run test-cargo-bench + afterBuild: xvfb-run pnpm dlx turbo@${TURBO_VERSION} run test-cargo-bench rust-check: name: rust check @@ -122,7 +123,7 @@ jobs: needsRust: 'yes' skipInstallBuild: 'yes' skipNativeBuild: 'yes' - afterBuild: turbo run rust-check + afterBuild: pnpm dlx turbo@${TURBO_VERSION} run rust-check secrets: inherit test-turbopack-dev: diff --git a/.github/workflows/build_reusable.yml b/.github/workflows/build_reusable.yml index 985e97fc295f1..f8822426054a7 100644 --- a/.github/workflows/build_reusable.yml +++ b/.github/workflows/build_reusable.yml @@ -74,6 +74,7 @@ env: DD_ENV: 'ci' TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }} NEXT_TEST_JOB: 1 + COREPACK_ENABLE_STRICT: 0 jobs: build: @@ -90,7 +91,7 @@ jobs: - run: corepack enable - run: pwd - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 @@ -115,7 +116,7 @@ jobs: - run: rustc --version if: ${{ inputs.skipNativeBuild != 'yes' || inputs.needsNextest == 'yes' || inputs.needsRust == 'yes' }} - - run: corepack prepare --activate yarn@1.22.19 && npm i -g "turbo@${TURBO_VERSION}" "@napi-rs/cli@${NAPI_CLI_VERSION}" + - run: corepack prepare --activate yarn@1.22.19 && npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" - name: Cache on ${{ github.ref_name }} uses: ijjk/rust-cache@turbo-cache-v1.0.7 @@ -148,12 +149,12 @@ jobs: - run: node scripts/normalize-version-bump.js name: normalize versions - - run: turbo run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target x86_64-unknown-linux-gnu + - run: pnpm dlx turbo@${TURBO_VERSION} run build-native-release -vvv --remote-cache-timeout 90 --summarize -- --target x86_64-unknown-linux-gnu if: ${{ inputs.skipNativeBuild != 'yes' && steps.docs-change.outputs.DOCS_CHANGE == 'nope' }} - name: Upload next-swc artifact if: ${{ inputs.uploadSwcArtifact == 'yes' && steps.docs-change.outputs.DOCS_CHANGE == 'nope' }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: next-swc-binary path: packages/next-swc/native/next-swc.linux-x64-gnu.node @@ -176,30 +177,30 @@ jobs: - run: pnpm playwright install chromium if: ${{ inputs.skipInstallBuild != 'yes' }} - - run: turbo run get-test-timings -- --build ${{ github.sha }} + - run: pnpm turbo run get-test-timings -- --build ${{ github.sha }} - run: /bin/bash -c "${{ inputs.afterBuild }}" if: ${{(inputs.skipForDocsOnly != 'yes' || steps.docs-change.outputs.DOCS_CHANGE == 'nope') && (inputs.skipForRelease != 'yes' || steps.is-release.outputs.IS_RELEASE == 'nope')}} - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: turbo run summary - path: .turbo/runs - - - name: Upload test reports artifact - uses: actions/upload-artifact@v3 - if: ${{ inputs.afterBuild }} - with: - name: Test trace reports - path: | - test/test-junit-report - test/turbopack-test-junit-report - if-no-files-found: ignore + # - name: Upload artifact + # uses: actions/upload-artifact@v4 + # with: + # name: turbo run summary + # path: .turbo/runs + + # - name: Upload test reports artifact + # uses: actions/upload-artifact@v4 + # if: ${{ inputs.afterBuild }} + # with: + # name: Test trace reports + # path: | + # test/test-junit-report + # test/turbopack-test-junit-report + # if-no-files-found: ignore - name: Download test reports artifact id: download-test-reports - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 continue-on-error: true if: ${{ inputs.uploadTestTrace == 'yes' && (inputs.skipForDocsOnly != 'yes' || steps.docs-change.outputs.DOCS_CHANGE == 'nope') }} with: diff --git a/.github/workflows/code_freeze.yml b/.github/workflows/code_freeze.yml index 48b20b36c86b2..172a4eede8224 100644 --- a/.github/workflows/code_freeze.yml +++ b/.github/workflows/code_freeze.yml @@ -28,7 +28,7 @@ jobs: environment: release-${{ github.event.inputs.releaseType }} steps: - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 check-latest: true diff --git a/.github/workflows/pull_request_approved.yml b/.github/workflows/pull_request_approved.yml index 77519be02f1a6..ddb098b42d6f0 100644 --- a/.github/workflows/pull_request_approved.yml +++ b/.github/workflows/pull_request_approved.yml @@ -10,8 +10,8 @@ jobs: if: github.repository_owner == 'vercel' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: 18 - run: corepack enable diff --git a/.github/workflows/pull_request_stats.yml b/.github/workflows/pull_request_stats.yml index b1d9e448288e5..9f9d0ee586742 100644 --- a/.github/workflows/pull_request_stats.yml +++ b/.github/workflows/pull_request_stats.yml @@ -38,7 +38,7 @@ jobs: - 'x64' - 'metal' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 @@ -46,7 +46,7 @@ jobs: run: echo "DOCS_CHANGE<> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.js --not --type docs --exec echo 'nope')" >> $GITHUB_OUTPUT; echo 'EOF' >> $GITHUB_OUTPUT id: docs-change - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }} with: name: next-swc-binary diff --git a/.github/workflows/test_e2e_deploy.yml b/.github/workflows/test_e2e_deploy.yml index 40d286861c884..b1bd1c6b13ecd 100644 --- a/.github/workflows/test_e2e_deploy.yml +++ b/.github/workflows/test_e2e_deploy.yml @@ -31,13 +31,13 @@ jobs: steps: - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_LTS_VERSION }} check-latest: true - run: corepack enable - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 @@ -55,7 +55,7 @@ jobs: - name: Upload test trace if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: test-trace if-no-files-found: ignore diff --git a/.github/workflows/test_examples.yml b/.github/workflows/test_examples.yml index 11518dd209b22..e8a60b830ede7 100644 --- a/.github/workflows/test_examples.yml +++ b/.github/workflows/test_examples.yml @@ -27,7 +27,7 @@ jobs: matrix: node: [16, 18] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 25 # https://github.com/actions/virtual-environments/issues/1187 @@ -35,7 +35,7 @@ jobs: run: sudo ethtool -K eth0 tx off rx off - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 16 check-latest: true diff --git a/.github/workflows/trigger_release.yml b/.github/workflows/trigger_release.yml index 2e097befe4616..1bb466e891f28 100644 --- a/.github/workflows/trigger_release.yml +++ b/.github/workflows/trigger_release.yml @@ -45,7 +45,7 @@ jobs: environment: release-${{ github.event.inputs.releaseType || 'canary' }} steps: - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 check-latest: true @@ -63,7 +63,7 @@ jobs: - id: get-store-path run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - uses: actions/cache@v4 timeout-minutes: 5 id: cache-pnpm-store with: diff --git a/.github/workflows/update_fonts_data.yml b/.github/workflows/update_fonts_data.yml index c47e205bf75c9..2e16261fd7c92 100644 --- a/.github/workflows/update_fonts_data.yml +++ b/.github/workflows/update_fonts_data.yml @@ -15,14 +15,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # Commits made with the default `GITHUB_TOKEN` won't trigger workflows. # See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_LTS_VERSION }} check-latest: true diff --git a/packages/next/src/server/lib/router-server.ts b/packages/next/src/server/lib/router-server.ts index c725f6d70141e..62e4491cdd21e 100644 --- a/packages/next/src/server/lib/router-server.ts +++ b/packages/next/src/server/lib/router-server.ts @@ -34,6 +34,7 @@ import { } from '../../shared/lib/constants' import { DevBundlerService } from './dev-bundler-service' import type { TLSSocket } from 'tls' +import { filterInternalHeaders } from './server-ipc/utils' const debug = setupDebug('next:router-server:main') @@ -133,6 +134,16 @@ 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[0] = { port: opts.port, dir: opts.dir, @@ -170,6 +181,11 @@ export async function initialize(opts: { ) const requestHandlerImpl: WorkerRequestHandler = async (req, res) => { + // internal headers should not be honored by the request handler + if (!process.env.NEXT_PRIVATE_TEST_HEADERS) { + filterInternalHeaders(req.headers) + } + if (compress) { // @ts-expect-error not express req/res compress(req, res, () => {}) diff --git a/packages/next/src/server/lib/server-ipc/utils.ts b/packages/next/src/server/lib/server-ipc/utils.ts index 06a981d166bd0..5d276d4b9f300 100644 --- a/packages/next/src/server/lib/server-ipc/utils.ts +++ b/packages/next/src/server/lib/server-ipc/utils.ts @@ -35,3 +35,36 @@ export const filterReqHeaders = ( } return headers as Record } + +// These are headers that are only used internally and should +// not be honored from the external request +const INTERNAL_HEADERS = [ + 'x-middleware-rewrite', + 'x-middleware-redirect', + 'x-middleware-set-cookie', + 'x-middleware-skip', + 'x-middleware-override-headers', + 'x-middleware-next', + 'x-now-route-matches', + 'x-matched-path', +] +export const filterInternalHeaders = ( + headers: Record +) => { + for (const header in headers) { + 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'] + } + } +} diff --git a/packages/next/src/server/web/sandbox/context.ts b/packages/next/src/server/web/sandbox/context.ts index 11e04bf577304..99e84a5ad46ae 100644 --- a/packages/next/src/server/web/sandbox/context.ts +++ b/packages/next/src/server/web/sandbox/context.ts @@ -313,7 +313,12 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`), 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`) diff --git a/test/e2e/middleware-general/test/index.test.ts b/test/e2e/middleware-general/test/index.test.ts index 67eef628b108b..c1135bb39c92e 100644 --- a/test/e2e/middleware-general/test/index.test.ts +++ b/test/e2e/middleware-general/test/index.test.ts @@ -102,6 +102,19 @@ 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') diff --git a/test/integration/required-server-files-ssr-404/test/index.test.js b/test/integration/required-server-files-ssr-404/test/index.test.js index 0e77419ce1f7c..0f511bb4c5bae 100644 --- a/test/integration/required-server-files-ssr-404/test/index.test.js +++ b/test/integration/required-server-files-ssr-404/test/index.test.js @@ -42,6 +42,7 @@ describe('Required Server Files', () => { } await fs.rename(join(appDir, 'pages'), join(appDir, 'pages-bak')) + process.env.NEXT_PRIVATE_TEST_HEADERS = '1' nextApp = nextServer({ conf: {}, dir: appDir, @@ -55,6 +56,7 @@ describe('Required Server Files', () => { console.log(`Listening at ::${appPort}`) }) afterAll(async () => { + delete process.env.NEXT_PRIVATE_TEST_HEADERS if (server) server.close() await fs.rename(join(appDir, 'pages-bak'), join(appDir, 'pages')) }) diff --git a/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts b/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts index b4c2b18b64154..3d1116e5fa719 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files-app.test.ts @@ -25,6 +25,7 @@ describe('required server files app router', () => { }) => { // test build against environment with next support process.env.NOW_BUILDER = nextEnv ? '1' : '' + process.env.NEXT_PRIVATE_TEST_HEADERS = '1' next = await createNext({ files: { @@ -92,6 +93,7 @@ describe('required server files app router', () => { await setupNext({ nextEnv: true, minimalMode: true }) }) afterAll(async () => { + delete process.env.NEXT_PRIVATE_TEST_HEADERS await next.destroy() if (server) await killApp(server) }) diff --git a/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts b/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts index 32b3c59d45012..7320931e83292 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts @@ -38,6 +38,7 @@ describe('required server files i18n', () => { wasmPkgIsAvailable = true console.warn(`Testing wasm fallback handling`) } + process.env.NEXT_PRIVATE_TEST_HEADERS = '1' next = await createNext({ files: { @@ -127,6 +128,7 @@ describe('required server files i18n', () => { ) }) afterAll(async () => { + delete process.env.NEXT_PRIVATE_TEST_HEADERS await next.destroy() if (server) await killApp(server) }) diff --git a/test/production/standalone-mode/required-server-files/required-server-files.test.ts b/test/production/standalone-mode/required-server-files/required-server-files.test.ts index 0bab6b06c5cef..2f79782de8cf1 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files.test.ts @@ -32,6 +32,7 @@ describe('required server files', () => { }) => { // test build against environment with next support process.env.NOW_BUILDER = nextEnv ? '1' : '' + process.env.NEXT_PRIVATE_TEST_HEADERS = '1' next = await createNext({ files: { @@ -140,6 +141,7 @@ describe('required server files', () => { await setupNext({ nextEnv: true, minimalMode: true }) }) afterAll(async () => { + delete process.env.NEXT_PRIVATE_TEST_HEADERS await next.destroy() if (server) await killApp(server) }) diff --git a/test/production/standalone-mode/response-cache/index.test.ts b/test/production/standalone-mode/response-cache/index.test.ts index ea934f04c2a33..55b14cd04d481 100644 --- a/test/production/standalone-mode/response-cache/index.test.ts +++ b/test/production/standalone-mode/response-cache/index.test.ts @@ -21,6 +21,7 @@ describe('minimal-mode-response-cache', () => { beforeAll(async () => { // test build against environment with next support process.env.NOW_BUILDER = '1' + process.env.NEXT_PRIVATE_TEST_HEADERS = '1' next = await createNext({ files: new FileRef(join(__dirname, 'app')), @@ -82,6 +83,7 @@ describe('minimal-mode-response-cache', () => { ) }) afterAll(async () => { + delete process.env.NEXT_PRIVATE_TEST_HEADERS await next.destroy() if (server) await killApp(server) })