vinext 0.0.29 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/build/prerender.d.ts +188 -0
- package/dist/build/prerender.js +675 -0
- package/dist/build/prerender.js.map +1 -0
- package/dist/build/report.d.ts +45 -46
- package/dist/build/report.js +247 -276
- package/dist/build/report.js.map +1 -1
- package/dist/build/run-prerender.d.ts +62 -0
- package/dist/build/run-prerender.js +183 -0
- package/dist/build/run-prerender.js.map +1 -0
- package/dist/build/server-manifest.d.ts +19 -0
- package/dist/build/server-manifest.js +29 -0
- package/dist/build/server-manifest.js.map +1 -0
- package/dist/build/static-export.d.ts +51 -66
- package/dist/build/static-export.js +51 -545
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.d.ts +26 -24
- package/dist/check.js +591 -567
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +1 -15
- package/dist/cli.js +430 -491
- package/dist/cli.js.map +1 -1
- package/dist/client/entry.d.ts +1 -2
- package/dist/client/entry.js +49 -62
- package/dist/client/entry.js.map +1 -1
- package/dist/client/validate-module-path.d.ts +4 -1
- package/dist/client/validate-module-path.js +23 -28
- package/dist/client/validate-module-path.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +15 -20
- package/dist/client/vinext-next-data.js +0 -1
- package/dist/cloudflare/index.d.ts +3 -8
- package/dist/cloudflare/index.js +3 -8
- package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
- package/dist/cloudflare/kv-cache-handler.js +354 -366
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +36 -34
- package/dist/cloudflare/tpr.js +460 -603
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +31 -40
- package/dist/config/config-matchers.js +727 -936
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/dotenv.d.ts +18 -11
- package/dist/config/dotenv.js +79 -84
- package/dist/config/dotenv.js.map +1 -1
- package/dist/config/next-config.d.ts +156 -146
- package/dist/config/next-config.js +374 -464
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +87 -96
- package/dist/deploy.js +490 -628
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +4 -1
- package/dist/entries/app-browser-entry.js +12 -8
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +33 -20
- package/dist/entries/app-rsc-entry.js +618 -343
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +9 -1
- package/dist/entries/app-ssr-entry.js +61 -28
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.d.ts +6 -2
- package/dist/entries/pages-client-entry.js +30 -33
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-entry-helpers.d.ts +5 -1
- package/dist/entries/pages-entry-helpers.js +17 -14
- package/dist/entries/pages-entry-helpers.js.map +1 -1
- package/dist/entries/pages-server-entry.d.ts +6 -2
- package/dist/entries/pages-server-entry.js +229 -207
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.d.ts +82 -62
- package/dist/index.js +2172 -3125
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +40 -37
- package/dist/init.js +201 -258
- package/dist/init.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +7 -3
- package/dist/plugins/async-hooks-stub.js +39 -42
- package/dist/plugins/async-hooks-stub.js.map +1 -1
- package/dist/plugins/client-reference-dedup.d.ts +7 -3
- package/dist/plugins/client-reference-dedup.js +63 -88
- package/dist/plugins/client-reference-dedup.js.map +1 -1
- package/dist/routing/app-router.d.ts +100 -96
- package/dist/routing/app-router.js +563 -659
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +18 -15
- package/dist/routing/file-matcher.js +65 -65
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.d.ts +23 -24
- package/dist/routing/pages-router.js +147 -172
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-trie.d.ts +23 -20
- package/dist/routing/route-trie.js +131 -151
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.d.ts +5 -2
- package/dist/routing/route-validation.js +98 -130
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +10 -7
- package/dist/routing/utils.js +75 -111
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.d.ts +8 -13
- package/dist/server/api-handler.js +161 -193
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-router-entry.d.ts +6 -16
- package/dist/server/app-router-entry.js +26 -54
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +11 -64
- package/dist/server/dev-module-runner.js +89 -101
- package/dist/server/dev-module-runner.js.map +1 -1
- package/dist/server/dev-origin-check.d.ts +12 -10
- package/dist/server/dev-origin-check.js +98 -108
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.d.ts +17 -13
- package/dist/server/dev-server.js +547 -874
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/html.d.ts +4 -1
- package/dist/server/html.js +25 -26
- package/dist/server/html.js.map +1 -1
- package/dist/server/image-optimization.d.ts +31 -28
- package/dist/server/image-optimization.js +183 -200
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation.d.ts +25 -22
- package/dist/server/instrumentation.js +110 -122
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/isr-cache.d.ts +16 -26
- package/dist/server/isr-cache.js +109 -126
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +85 -88
- package/dist/server/metadata-routes.js +277 -286
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-codegen.d.ts +7 -4
- package/dist/server/middleware-codegen.js +98 -65
- package/dist/server/middleware-codegen.js.map +1 -1
- package/dist/server/middleware-request-headers.d.ts +8 -6
- package/dist/server/middleware-request-headers.js +47 -65
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware.d.ts +31 -47
- package/dist/server/middleware.js +276 -363
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/normalize-path.d.ts +4 -1
- package/dist/server/normalize-path.js +33 -47
- package/dist/server/normalize-path.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +58 -0
- package/dist/server/pages-i18n.js +125 -0
- package/dist/server/pages-i18n.js.map +1 -0
- package/dist/server/prod-server.d.ts +19 -31
- package/dist/server/prod-server.js +714 -945
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-log.d.ts +18 -12
- package/dist/server/request-log.js +45 -52
- package/dist/server/request-log.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +9 -17
- package/dist/server/request-pipeline.js +133 -184
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/worker-utils.d.ts +4 -1
- package/dist/server/worker-utils.js +31 -37
- package/dist/server/worker-utils.js.map +1 -1
- package/dist/shims/amp.d.ts +5 -2
- package/dist/shims/amp.js +19 -15
- package/dist/shims/amp.js.map +1 -1
- package/dist/shims/app.d.ts +8 -10
- package/dist/shims/app.js +0 -1
- package/dist/shims/cache-runtime.d.ts +21 -43
- package/dist/shims/cache-runtime.js +271 -405
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +131 -119
- package/dist/shims/cache.js +339 -418
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/client-only.d.ts +1 -18
- package/dist/shims/client-only.js +0 -17
- package/dist/shims/compat-router.d.ts +4 -1
- package/dist/shims/compat-router.js +23 -19
- package/dist/shims/compat-router.js.map +1 -1
- package/dist/shims/config.d.ts +7 -5
- package/dist/shims/config.js +16 -23
- package/dist/shims/config.js.map +1 -1
- package/dist/shims/constants.d.ts +119 -118
- package/dist/shims/constants.js +159 -165
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/document.d.ts +20 -16
- package/dist/shims/document.js +41 -22
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/dynamic.d.ts +13 -22
- package/dist/shims/dynamic.js +122 -136
- package/dist/shims/dynamic.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +22 -15
- package/dist/shims/error-boundary.js +81 -79
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/error.d.ts +11 -12
- package/dist/shims/error.js +35 -39
- package/dist/shims/error.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +26 -10
- package/dist/shims/fetch-cache.js +443 -586
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +28 -26
- package/dist/shims/font-google-base.js +238 -325
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/font-google.d.ts +3 -3
- package/dist/shims/font-google.generated.d.ts +1928 -1924
- package/dist/shims/font-google.generated.js +1928 -2133
- package/dist/shims/font-google.generated.js.map +1 -1
- package/dist/shims/font-google.js +3 -3
- package/dist/shims/font-local.d.ts +28 -26
- package/dist/shims/font-local.js +204 -260
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/form.d.ts +13 -27
- package/dist/shims/form.js +128 -180
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/head-state.d.ts +9 -10
- package/dist/shims/head-state.js +25 -39
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/head.d.ts +16 -18
- package/dist/shims/head.js +185 -153
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +84 -71
- package/dist/shims/headers.js +447 -583
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-context.d.ts +23 -0
- package/dist/shims/i18n-context.js +44 -0
- package/dist/shims/i18n-context.js.map +1 -0
- package/dist/shims/i18n-state.d.ts +14 -0
- package/dist/shims/i18n-state.js +45 -0
- package/dist/shims/i18n-state.js.map +1 -0
- package/dist/shims/image-config.d.ts +11 -8
- package/dist/shims/image-config.js +50 -83
- package/dist/shims/image-config.js.map +1 -1
- package/dist/shims/image.d.ts +37 -44
- package/dist/shims/image.js +284 -301
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/api-utils.d.ts +7 -4
- package/dist/shims/internal/api-utils.js +0 -6
- package/dist/shims/internal/app-router-context.d.ts +22 -17
- package/dist/shims/internal/app-router-context.js +17 -13
- package/dist/shims/internal/app-router-context.js.map +1 -1
- package/dist/shims/internal/cookies.d.ts +2 -9
- package/dist/shims/internal/cookies.js +2 -9
- package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
- package/dist/shims/internal/parse-cookie-header.js +29 -29
- package/dist/shims/internal/parse-cookie-header.js.map +1 -1
- package/dist/shims/internal/router-context.d.ts +6 -1
- package/dist/shims/internal/router-context.js +11 -7
- package/dist/shims/internal/router-context.js.map +1 -1
- package/dist/shims/internal/utils.d.ts +40 -36
- package/dist/shims/internal/utils.js +24 -30
- package/dist/shims/internal/utils.js.map +1 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
- package/dist/shims/internal/work-unit-async-storage.js +14 -11
- package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
- package/dist/shims/layout-segment-context.d.ts +11 -14
- package/dist/shims/layout-segment-context.js +24 -23
- package/dist/shims/layout-segment-context.js.map +1 -1
- package/dist/shims/legacy-image.d.ts +39 -46
- package/dist/shims/legacy-image.js +47 -42
- package/dist/shims/legacy-image.js.map +1 -1
- package/dist/shims/link.d.ts +32 -36
- package/dist/shims/link.js +262 -382
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +210 -202
- package/dist/shims/metadata.js +545 -544
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.d.ts +19 -13
- package/dist/shims/navigation-state.js +68 -58
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +59 -63
- package/dist/shims/navigation.js +508 -690
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +2 -20
- package/dist/shims/og.js +2 -19
- package/dist/shims/readonly-url-search-params.d.ts +8 -5
- package/dist/shims/readonly-url-search-params.js +26 -22
- package/dist/shims/readonly-url-search-params.js.map +1 -1
- package/dist/shims/request-context.d.ts +8 -5
- package/dist/shims/request-context.js +50 -51
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +11 -0
- package/dist/shims/request-state-types.js +1 -0
- package/dist/shims/router-state.d.ts +15 -1
- package/dist/shims/router-state.js +34 -41
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +81 -81
- package/dist/shims/router.js +517 -543
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.d.ts +39 -48
- package/dist/shims/script.js +107 -160
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server-only.d.ts +1 -19
- package/dist/shims/server-only.js +0 -18
- package/dist/shims/server.d.ts +175 -157
- package/dist/shims/server.js +462 -432
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +66 -0
- package/dist/shims/unified-request-context.js +98 -0
- package/dist/shims/unified-request-context.js.map +1 -0
- package/dist/shims/url-safety.d.ts +4 -1
- package/dist/shims/url-safety.js +15 -11
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/shims/url-utils.d.ts +8 -5
- package/dist/shims/url-utils.js +62 -93
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/shims/web-vitals.d.ts +10 -8
- package/dist/shims/web-vitals.js +9 -15
- package/dist/shims/web-vitals.js.map +1 -1
- package/dist/utils/base-path.d.ts +5 -2
- package/dist/utils/base-path.js +21 -19
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +26 -0
- package/dist/utils/domain-locale.js +44 -0
- package/dist/utils/domain-locale.js.map +1 -0
- package/dist/utils/hash.d.ts +4 -1
- package/dist/utils/hash.js +19 -17
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/manifest-paths.d.ts +6 -3
- package/dist/utils/manifest-paths.js +15 -16
- package/dist/utils/manifest-paths.js.map +1 -1
- package/dist/utils/project.d.ts +13 -11
- package/dist/utils/project.js +169 -216
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/query.d.ts +8 -6
- package/dist/utils/query.js +57 -67
- package/dist/utils/query.js.map +1 -1
- package/package.json +11 -10
- package/dist/build/report.d.ts.map +0 -1
- package/dist/build/static-export.d.ts.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/client/entry.d.ts.map +0 -1
- package/dist/client/validate-module-path.d.ts.map +0 -1
- package/dist/client/vinext-next-data.d.ts.map +0 -1
- package/dist/client/vinext-next-data.js.map +0 -1
- package/dist/cloudflare/index.d.ts.map +0 -1
- package/dist/cloudflare/index.js.map +0 -1
- package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
- package/dist/cloudflare/tpr.d.ts.map +0 -1
- package/dist/config/config-matchers.d.ts.map +0 -1
- package/dist/config/dotenv.d.ts.map +0 -1
- package/dist/config/next-config.d.ts.map +0 -1
- package/dist/deploy.d.ts.map +0 -1
- package/dist/entries/app-browser-entry.d.ts.map +0 -1
- package/dist/entries/app-rsc-entry.d.ts.map +0 -1
- package/dist/entries/app-ssr-entry.d.ts.map +0 -1
- package/dist/entries/pages-client-entry.d.ts.map +0 -1
- package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
- package/dist/entries/pages-server-entry.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
- package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
- package/dist/routing/app-router.d.ts.map +0 -1
- package/dist/routing/file-matcher.d.ts.map +0 -1
- package/dist/routing/pages-router.d.ts.map +0 -1
- package/dist/routing/route-trie.d.ts.map +0 -1
- package/dist/routing/route-validation.d.ts.map +0 -1
- package/dist/routing/utils.d.ts.map +0 -1
- package/dist/server/api-handler.d.ts.map +0 -1
- package/dist/server/app-router-entry.d.ts.map +0 -1
- package/dist/server/dev-module-runner.d.ts.map +0 -1
- package/dist/server/dev-origin-check.d.ts.map +0 -1
- package/dist/server/dev-server.d.ts.map +0 -1
- package/dist/server/html.d.ts.map +0 -1
- package/dist/server/image-optimization.d.ts.map +0 -1
- package/dist/server/instrumentation.d.ts.map +0 -1
- package/dist/server/isr-cache.d.ts.map +0 -1
- package/dist/server/metadata-routes.d.ts.map +0 -1
- package/dist/server/middleware-codegen.d.ts.map +0 -1
- package/dist/server/middleware-request-headers.d.ts.map +0 -1
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/normalize-path.d.ts.map +0 -1
- package/dist/server/prod-server.d.ts.map +0 -1
- package/dist/server/request-log.d.ts.map +0 -1
- package/dist/server/request-pipeline.d.ts.map +0 -1
- package/dist/server/worker-utils.d.ts.map +0 -1
- package/dist/shims/amp.d.ts.map +0 -1
- package/dist/shims/app.d.ts.map +0 -1
- package/dist/shims/app.js.map +0 -1
- package/dist/shims/cache-runtime.d.ts.map +0 -1
- package/dist/shims/cache.d.ts.map +0 -1
- package/dist/shims/client-only.d.ts.map +0 -1
- package/dist/shims/client-only.js.map +0 -1
- package/dist/shims/compat-router.d.ts.map +0 -1
- package/dist/shims/config.d.ts.map +0 -1
- package/dist/shims/constants.d.ts.map +0 -1
- package/dist/shims/document.d.ts.map +0 -1
- package/dist/shims/dynamic.d.ts.map +0 -1
- package/dist/shims/error-boundary.d.ts.map +0 -1
- package/dist/shims/error.d.ts.map +0 -1
- package/dist/shims/fetch-cache.d.ts.map +0 -1
- package/dist/shims/font-google-base.d.ts.map +0 -1
- package/dist/shims/font-google.d.ts.map +0 -1
- package/dist/shims/font-google.generated.d.ts.map +0 -1
- package/dist/shims/font-google.js.map +0 -1
- package/dist/shims/font-local.d.ts.map +0 -1
- package/dist/shims/form.d.ts.map +0 -1
- package/dist/shims/head-state.d.ts.map +0 -1
- package/dist/shims/head.d.ts.map +0 -1
- package/dist/shims/headers.d.ts.map +0 -1
- package/dist/shims/image-config.d.ts.map +0 -1
- package/dist/shims/image.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.js.map +0 -1
- package/dist/shims/internal/app-router-context.d.ts.map +0 -1
- package/dist/shims/internal/cookies.d.ts.map +0 -1
- package/dist/shims/internal/cookies.js.map +0 -1
- package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
- package/dist/shims/internal/router-context.d.ts.map +0 -1
- package/dist/shims/internal/utils.d.ts.map +0 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
- package/dist/shims/layout-segment-context.d.ts.map +0 -1
- package/dist/shims/legacy-image.d.ts.map +0 -1
- package/dist/shims/link.d.ts.map +0 -1
- package/dist/shims/metadata.d.ts.map +0 -1
- package/dist/shims/navigation-state.d.ts.map +0 -1
- package/dist/shims/navigation.d.ts.map +0 -1
- package/dist/shims/og.d.ts.map +0 -1
- package/dist/shims/og.js.map +0 -1
- package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
- package/dist/shims/request-context.d.ts.map +0 -1
- package/dist/shims/router-state.d.ts.map +0 -1
- package/dist/shims/router.d.ts.map +0 -1
- package/dist/shims/script.d.ts.map +0 -1
- package/dist/shims/server-only.d.ts.map +0 -1
- package/dist/shims/server-only.js.map +0 -1
- package/dist/shims/server.d.ts.map +0 -1
- package/dist/shims/url-safety.d.ts.map +0 -1
- package/dist/shims/url-utils.d.ts.map +0 -1
- package/dist/shims/web-vitals.d.ts.map +0 -1
- package/dist/utils/base-path.d.ts.map +0 -1
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/manifest-paths.d.ts.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/query.d.ts.map +0 -1
package/dist/shims/headers.js
CHANGED
|
@@ -1,658 +1,522 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* next/headers shim
|
|
3
|
-
*
|
|
4
|
-
* Provides cookies() and headers() functions for App Router Server Components.
|
|
5
|
-
* These read from a request context set by the RSC handler before rendering.
|
|
6
|
-
*
|
|
7
|
-
* In Next.js 15+, cookies() and headers() return Promises (async).
|
|
8
|
-
* We support both the sync (legacy) and async patterns.
|
|
9
|
-
*/
|
|
10
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
1
|
import { buildRequestHeadersFromMiddlewareResponse } from "../server/middleware-request-headers.js";
|
|
12
2
|
import { parseCookieHeader } from "./internal/parse-cookie-header.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
//#region src/shims/headers.ts
|
|
6
|
+
/**
|
|
7
|
+
* next/headers shim
|
|
8
|
+
*
|
|
9
|
+
* Provides cookies() and headers() functions for App Router Server Components.
|
|
10
|
+
* These read from a request context set by the RSC handler before rendering.
|
|
11
|
+
*
|
|
12
|
+
* In Next.js 15+, cookies() and headers() return Promises (async).
|
|
13
|
+
* We support both the sync (legacy) and async patterns.
|
|
14
|
+
*/
|
|
20
15
|
const _ALS_KEY = Symbol.for("vinext.nextHeadersShim.als");
|
|
21
16
|
const _FALLBACK_KEY = Symbol.for("vinext.nextHeadersShim.fallback");
|
|
22
17
|
const _g = globalThis;
|
|
23
|
-
const _als =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
const _als = _g[_ALS_KEY] ??= new AsyncLocalStorage();
|
|
19
|
+
const _fallbackState = _g[_FALLBACK_KEY] ??= {
|
|
20
|
+
headersContext: null,
|
|
21
|
+
dynamicUsageDetected: false,
|
|
22
|
+
pendingSetCookies: [],
|
|
23
|
+
draftModeCookieHeader: null,
|
|
24
|
+
phase: "render"
|
|
25
|
+
};
|
|
26
|
+
const EXPIRED_COOKIE_DATE = (/* @__PURE__ */ new Date(0)).toUTCString();
|
|
32
27
|
function _getState() {
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
if (isInsideUnifiedScope()) return getRequestContext();
|
|
29
|
+
return _als.getStore() ?? _fallbackState;
|
|
35
30
|
}
|
|
36
31
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// (stored on _state)
|
|
32
|
+
* Dynamic usage flag — set when a component calls connection(), cookies(),
|
|
33
|
+
* headers(), or noStore() during rendering. When true, ISR caching is
|
|
34
|
+
* bypassed and the response gets Cache-Control: no-store.
|
|
35
|
+
*/
|
|
42
36
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
* Mark the current render as requiring dynamic (uncached) rendering.
|
|
38
|
+
* Called by connection(), cookies(), headers(), and noStore().
|
|
39
|
+
*/
|
|
40
|
+
function markDynamicUsage() {
|
|
41
|
+
_getState().dynamicUsageDetected = true;
|
|
48
42
|
}
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Cache scope detection — checks whether we're inside "use cache" or
|
|
51
|
-
// unstable_cache() by reading ALS instances stored on globalThis via Symbols.
|
|
52
|
-
// This avoids circular imports between headers.ts, cache.ts, and cache-runtime.ts.
|
|
53
|
-
// The ALS instances are registered by cache-runtime.ts and cache.ts respectively.
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
43
|
/** Symbol used by cache-runtime.ts to store the "use cache" ALS on globalThis */
|
|
56
44
|
const _USE_CACHE_ALS_KEY = Symbol.for("vinext.cacheRuntime.contextAls");
|
|
57
45
|
/** Symbol used by cache.ts to store the unstable_cache ALS on globalThis */
|
|
58
46
|
const _UNSTABLE_CACHE_ALS_KEY = Symbol.for("vinext.unstableCache.als");
|
|
59
47
|
const _gHeaders = globalThis;
|
|
60
48
|
function _isInsideUseCache() {
|
|
61
|
-
|
|
62
|
-
return als?.getStore() != null;
|
|
49
|
+
return _gHeaders[_USE_CACHE_ALS_KEY]?.getStore() != null;
|
|
63
50
|
}
|
|
64
51
|
function _isInsideUnstableCache() {
|
|
65
|
-
|
|
66
|
-
return als?.getStore() === true;
|
|
52
|
+
return _gHeaders[_UNSTABLE_CACHE_ALS_KEY]?.getStore() === true;
|
|
67
53
|
}
|
|
68
54
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
`If you need this data inside a cached function, call \`${apiName}\` ` +
|
|
79
|
-
"outside and pass the required data as an argument.");
|
|
80
|
-
}
|
|
81
|
-
if (_isInsideUnstableCache()) {
|
|
82
|
-
throw new Error(`\`${apiName}\` cannot be called inside a function cached with \`unstable_cache()\`. ` +
|
|
83
|
-
`If you need this data inside a cached function, call \`${apiName}\` ` +
|
|
84
|
-
"outside and pass the required data as an argument.");
|
|
85
|
-
}
|
|
55
|
+
* Throw if the current execution is inside a "use cache" or unstable_cache()
|
|
56
|
+
* scope. Called by dynamic request APIs (headers, cookies, connection) to
|
|
57
|
+
* prevent request-specific data from being frozen into cached results.
|
|
58
|
+
*
|
|
59
|
+
* @param apiName - The name of the API being called (e.g. "connection()")
|
|
60
|
+
*/
|
|
61
|
+
function throwIfInsideCacheScope(apiName) {
|
|
62
|
+
if (_isInsideUseCache()) throw new Error(`\`${apiName}\` cannot be called inside "use cache". If you need this data inside a cached function, call \`${apiName}\` outside and pass the required data as an argument.`);
|
|
63
|
+
if (_isInsideUnstableCache()) throw new Error(`\`${apiName}\` cannot be called inside a function cached with \`unstable_cache()\`. If you need this data inside a cached function, call \`${apiName}\` outside and pass the required data as an argument.`);
|
|
86
64
|
}
|
|
87
65
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
66
|
+
* Check and reset the dynamic usage flag.
|
|
67
|
+
* Called by the server after rendering to decide on caching.
|
|
68
|
+
*/
|
|
69
|
+
function consumeDynamicUsage() {
|
|
70
|
+
const state = _getState();
|
|
71
|
+
const used = state.dynamicUsageDetected;
|
|
72
|
+
state.dynamicUsageDetected = false;
|
|
73
|
+
return used;
|
|
96
74
|
}
|
|
97
75
|
function _setStatePhase(state, phase) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
const previous = state.phase;
|
|
77
|
+
state.phase = phase;
|
|
78
|
+
return previous;
|
|
101
79
|
}
|
|
102
80
|
function _areCookiesMutableInCurrentPhase() {
|
|
103
|
-
|
|
104
|
-
|
|
81
|
+
const phase = _getState().phase;
|
|
82
|
+
return phase === "action" || phase === "route-handler";
|
|
105
83
|
}
|
|
106
|
-
|
|
107
|
-
|
|
84
|
+
function setHeadersAccessPhase(phase) {
|
|
85
|
+
return _setStatePhase(_getState(), phase);
|
|
108
86
|
}
|
|
109
87
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
88
|
+
* Set the headers/cookies context for the current RSC render.
|
|
89
|
+
* Called by the framework's RSC entry before rendering each request.
|
|
90
|
+
*
|
|
91
|
+
* @deprecated Prefer runWithHeadersContext() which uses als.run() for
|
|
92
|
+
* proper per-request isolation. This function mutates the ALS store
|
|
93
|
+
* in-place and is only safe for cleanup (ctx=null) within an existing
|
|
94
|
+
* als.run() scope.
|
|
95
|
+
*/
|
|
118
96
|
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
_fallbackState.headersContext = ctx;
|
|
141
|
-
_fallbackState.dynamicUsageDetected = false;
|
|
142
|
-
_fallbackState.pendingSetCookies = [];
|
|
143
|
-
_fallbackState.draftModeCookieHeader = null;
|
|
144
|
-
_fallbackState.phase = "render";
|
|
145
|
-
}
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
// End of request cleanup: keep the store (so consumeDynamicUsage and
|
|
149
|
-
// cookie flushing can still run), but clear the request headers/cookies.
|
|
150
|
-
const state = _als.getStore();
|
|
151
|
-
if (state) {
|
|
152
|
-
state.headersContext = null;
|
|
153
|
-
state.phase = "render";
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
_fallbackState.headersContext = null;
|
|
157
|
-
_fallbackState.phase = "render";
|
|
158
|
-
}
|
|
97
|
+
* Returns the current live HeadersContext from ALS (or the fallback).
|
|
98
|
+
* Used after applyMiddlewareRequestHeaders() to build a post-middleware
|
|
99
|
+
* request context for afterFiles/fallback rewrite has/missing evaluation.
|
|
100
|
+
*/
|
|
101
|
+
function getHeadersContext() {
|
|
102
|
+
return _getState().headersContext;
|
|
103
|
+
}
|
|
104
|
+
function setHeadersContext(ctx) {
|
|
105
|
+
const state = _getState();
|
|
106
|
+
if (ctx !== null) {
|
|
107
|
+
state.headersContext = ctx;
|
|
108
|
+
state.dynamicUsageDetected = false;
|
|
109
|
+
state.pendingSetCookies = [];
|
|
110
|
+
state.draftModeCookieHeader = null;
|
|
111
|
+
state.phase = "render";
|
|
112
|
+
} else {
|
|
113
|
+
state.headersContext = null;
|
|
114
|
+
state.phase = "render";
|
|
115
|
+
}
|
|
159
116
|
}
|
|
160
117
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
118
|
+
* Run a function with headers context, ensuring the context propagates
|
|
119
|
+
* through all async operations (including RSC streaming).
|
|
120
|
+
*
|
|
121
|
+
* Uses AsyncLocalStorage.run() to guarantee per-request isolation.
|
|
122
|
+
* The ALS store propagates through all async continuations including
|
|
123
|
+
* ReadableStream consumption, setTimeout callbacks, and Promise chains,
|
|
124
|
+
* so RSC streaming works correctly — components that render when the
|
|
125
|
+
* stream is consumed still see the correct request's context.
|
|
126
|
+
*/
|
|
127
|
+
function runWithHeadersContext(ctx, fn) {
|
|
128
|
+
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
|
|
129
|
+
uCtx.headersContext = ctx;
|
|
130
|
+
uCtx.dynamicUsageDetected = false;
|
|
131
|
+
uCtx.pendingSetCookies = [];
|
|
132
|
+
uCtx.draftModeCookieHeader = null;
|
|
133
|
+
uCtx.phase = "render";
|
|
134
|
+
}, fn);
|
|
135
|
+
const state = {
|
|
136
|
+
headersContext: ctx,
|
|
137
|
+
dynamicUsageDetected: false,
|
|
138
|
+
pendingSetCookies: [],
|
|
139
|
+
draftModeCookieHeader: null,
|
|
140
|
+
phase: "render"
|
|
141
|
+
};
|
|
142
|
+
return _als.run(state, fn);
|
|
179
143
|
}
|
|
180
144
|
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (nextCookieHeader !== null) {
|
|
205
|
-
const nextCookies = parseCookieHeader(nextCookieHeader);
|
|
206
|
-
for (const [name, value] of nextCookies) {
|
|
207
|
-
ctx.cookies.set(name, value);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
145
|
+
* Apply middleware-forwarded request headers to the current headers context.
|
|
146
|
+
*
|
|
147
|
+
* When Next.js middleware calls `NextResponse.next()` or `NextResponse.rewrite()`
|
|
148
|
+
* with `{ request: { headers } }`, the modified headers are encoded on the
|
|
149
|
+
* middleware response. This function decodes that protocol and applies the
|
|
150
|
+
* resulting request header set to the live `HeadersContext`. When an override
|
|
151
|
+
* list is present, omitted headers are deleted as part of the rebuild.
|
|
152
|
+
*/
|
|
153
|
+
function applyMiddlewareRequestHeaders(middlewareResponseHeaders) {
|
|
154
|
+
const state = _getState();
|
|
155
|
+
if (!state.headersContext) return;
|
|
156
|
+
const ctx = state.headersContext;
|
|
157
|
+
const previousCookieHeader = ctx.headers.get("cookie");
|
|
158
|
+
const nextHeaders = buildRequestHeadersFromMiddlewareResponse(ctx.headers, middlewareResponseHeaders);
|
|
159
|
+
if (!nextHeaders) return;
|
|
160
|
+
ctx.headers = nextHeaders;
|
|
161
|
+
const nextCookieHeader = nextHeaders.get("cookie");
|
|
162
|
+
if (previousCookieHeader === nextCookieHeader) return;
|
|
163
|
+
ctx.cookies.clear();
|
|
164
|
+
if (nextCookieHeader !== null) {
|
|
165
|
+
const nextCookies = parseCookieHeader(nextCookieHeader);
|
|
166
|
+
for (const [name, value] of nextCookies) ctx.cookies.set(name, value);
|
|
167
|
+
}
|
|
210
168
|
}
|
|
211
169
|
/** Methods on `Headers` that mutate state. Hoisted to module scope — static. */
|
|
212
|
-
const _HEADERS_MUTATING_METHODS = new Set([
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
170
|
+
const _HEADERS_MUTATING_METHODS = new Set([
|
|
171
|
+
"set",
|
|
172
|
+
"delete",
|
|
173
|
+
"append"
|
|
174
|
+
]);
|
|
175
|
+
var ReadonlyHeadersError = class ReadonlyHeadersError extends Error {
|
|
176
|
+
constructor() {
|
|
177
|
+
super("Headers cannot be modified. Read more: https://nextjs.org/docs/app/api-reference/functions/headers");
|
|
178
|
+
}
|
|
179
|
+
static callable() {
|
|
180
|
+
throw new ReadonlyHeadersError();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var ReadonlyRequestCookiesError = class ReadonlyRequestCookiesError extends Error {
|
|
184
|
+
constructor() {
|
|
185
|
+
super("Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options");
|
|
186
|
+
}
|
|
187
|
+
static callable() {
|
|
188
|
+
throw new ReadonlyRequestCookiesError();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
229
191
|
function _decorateRequestApiPromise(promise, target) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
});
|
|
192
|
+
return new Proxy(promise, {
|
|
193
|
+
get(promiseTarget, prop) {
|
|
194
|
+
if (prop in promiseTarget) {
|
|
195
|
+
const value = Reflect.get(promiseTarget, prop, promiseTarget);
|
|
196
|
+
return typeof value === "function" ? value.bind(promiseTarget) : value;
|
|
197
|
+
}
|
|
198
|
+
const value = Reflect.get(target, prop, target);
|
|
199
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
200
|
+
},
|
|
201
|
+
has(promiseTarget, prop) {
|
|
202
|
+
return prop in promiseTarget || prop in target;
|
|
203
|
+
},
|
|
204
|
+
ownKeys(promiseTarget) {
|
|
205
|
+
return Array.from(new Set([...Reflect.ownKeys(promiseTarget), ...Reflect.ownKeys(target)]));
|
|
206
|
+
},
|
|
207
|
+
getOwnPropertyDescriptor(promiseTarget, prop) {
|
|
208
|
+
return Reflect.getOwnPropertyDescriptor(promiseTarget, prop) ?? Reflect.getOwnPropertyDescriptor(target, prop);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
250
211
|
}
|
|
251
212
|
function _decorateRejectedRequestApiPromise(error) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (prop === "then" || prop === "catch" || prop === "finally") {
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
throw normalizedError;
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
return _decorateRequestApiPromise(promise, throwingTarget);
|
|
213
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
214
|
+
const promise = Promise.reject(normalizedError);
|
|
215
|
+
promise.catch(() => {});
|
|
216
|
+
return _decorateRequestApiPromise(promise, new Proxy({}, { get(_target, prop) {
|
|
217
|
+
if (prop === "then" || prop === "catch" || prop === "finally") return;
|
|
218
|
+
throw normalizedError;
|
|
219
|
+
} }));
|
|
266
220
|
}
|
|
267
221
|
function _sealHeaders(headers) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const value = Reflect.get(target, prop, target);
|
|
274
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
275
|
-
},
|
|
276
|
-
});
|
|
222
|
+
return new Proxy(headers, { get(target, prop) {
|
|
223
|
+
if (typeof prop === "string" && _HEADERS_MUTATING_METHODS.has(prop)) throw new ReadonlyHeadersError();
|
|
224
|
+
const value = Reflect.get(target, prop, target);
|
|
225
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
226
|
+
} });
|
|
277
227
|
}
|
|
278
228
|
function _wrapMutableCookies(cookies) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
const value = Reflect.get(target, prop, target);
|
|
290
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
291
|
-
},
|
|
292
|
-
});
|
|
229
|
+
return new Proxy(cookies, { get(target, prop) {
|
|
230
|
+
if (prop === "set" || prop === "delete") return (...args) => {
|
|
231
|
+
if (!_areCookiesMutableInCurrentPhase()) throw new ReadonlyRequestCookiesError();
|
|
232
|
+
return Reflect.get(target, prop, target).apply(target, args);
|
|
233
|
+
};
|
|
234
|
+
const value = Reflect.get(target, prop, target);
|
|
235
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
236
|
+
} });
|
|
293
237
|
}
|
|
294
238
|
function _sealCookies(cookies) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const value = Reflect.get(target, prop, target);
|
|
301
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
302
|
-
},
|
|
303
|
-
});
|
|
239
|
+
return new Proxy(cookies, { get(target, prop) {
|
|
240
|
+
if (prop === "set" || prop === "delete") throw new ReadonlyRequestCookiesError();
|
|
241
|
+
const value = Reflect.get(target, prop, target);
|
|
242
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
243
|
+
} });
|
|
304
244
|
}
|
|
305
245
|
function _getMutableCookies(ctx) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
return ctx.mutableCookies;
|
|
246
|
+
if (!ctx.mutableCookies) ctx.mutableCookies = _wrapMutableCookies(new RequestCookies(ctx.cookies));
|
|
247
|
+
return ctx.mutableCookies;
|
|
310
248
|
}
|
|
311
249
|
function _getReadonlyCookies(ctx) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// mutable phase-checking proxy while still reflecting the shared cookie map.
|
|
315
|
-
ctx.readonlyCookies = _sealCookies(new RequestCookies(ctx.cookies));
|
|
316
|
-
}
|
|
317
|
-
return ctx.readonlyCookies;
|
|
250
|
+
if (!ctx.readonlyCookies) ctx.readonlyCookies = _sealCookies(new RequestCookies(ctx.cookies));
|
|
251
|
+
return ctx.readonlyCookies;
|
|
318
252
|
}
|
|
319
253
|
function _getReadonlyHeaders(ctx) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
return ctx.readonlyHeaders;
|
|
254
|
+
if (!ctx.readonlyHeaders) ctx.readonlyHeaders = _sealHeaders(ctx.headers);
|
|
255
|
+
return ctx.readonlyHeaders;
|
|
324
256
|
}
|
|
325
257
|
/**
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
});
|
|
370
|
-
// ---------------------------------------------------------------------------
|
|
371
|
-
// Lazy cookie map
|
|
372
|
-
// ---------------------------------------------------------------------------
|
|
373
|
-
// Parsing cookies requires splitting on `;` and `=`, which is cheap but
|
|
374
|
-
// still unnecessary overhead if `cookies()` is never called for this request.
|
|
375
|
-
let _cookies = null;
|
|
376
|
-
function getCookies() {
|
|
377
|
-
if (_cookies)
|
|
378
|
-
return _cookies;
|
|
379
|
-
// Read from the proxy so middleware-modified cookie headers are respected.
|
|
380
|
-
const cookieHeader = headersProxy.get("cookie") || "";
|
|
381
|
-
_cookies = parseCookieHeader(cookieHeader);
|
|
382
|
-
return _cookies;
|
|
383
|
-
}
|
|
384
|
-
// Expose cookies as a lazy getter that memoises on first access.
|
|
385
|
-
const ctx = {
|
|
386
|
-
headers: headersProxy,
|
|
387
|
-
get cookies() {
|
|
388
|
-
return getCookies();
|
|
389
|
-
},
|
|
390
|
-
};
|
|
391
|
-
return ctx;
|
|
258
|
+
* Create a HeadersContext from a standard Request object.
|
|
259
|
+
*
|
|
260
|
+
* Performance note: In Workerd (Cloudflare Workers), `new Headers(request.headers)`
|
|
261
|
+
* copies the entire header map across the V8/C++ boundary, which shows up as
|
|
262
|
+
* ~815 ms self-time in production profiles when requests carry many headers.
|
|
263
|
+
* We defer this copy with a lazy proxy:
|
|
264
|
+
*
|
|
265
|
+
* - Reads (`get`, `has`, `entries`, …) are forwarded directly to the original
|
|
266
|
+
* immutable `request.headers` — zero copy cost on the hot path.
|
|
267
|
+
* - The first mutating call (`set`, `delete`, `append`) materialises
|
|
268
|
+
* `new Headers(request.headers)` once, then applies the mutation to the copy.
|
|
269
|
+
* All subsequent operations go to the copy.
|
|
270
|
+
*
|
|
271
|
+
* This means the ~815 ms copy only occurs when middleware actually rewrites
|
|
272
|
+
* request headers via `NextResponse.next({ request: { headers } })`, which is
|
|
273
|
+
* uncommon. Pure read requests (the vast majority) pay zero copy cost.
|
|
274
|
+
*
|
|
275
|
+
* Cookie parsing is also deferred: the `cookie` header string is not split
|
|
276
|
+
* until the first call to `cookies()` or `draftMode()`.
|
|
277
|
+
*/
|
|
278
|
+
function headersContextFromRequest(request) {
|
|
279
|
+
let _mutable = null;
|
|
280
|
+
const headersProxy = new Proxy(request.headers, { get(target, prop) {
|
|
281
|
+
const src = _mutable ?? target;
|
|
282
|
+
if (typeof prop === "string" && _HEADERS_MUTATING_METHODS.has(prop)) return (...args) => {
|
|
283
|
+
if (!_mutable) _mutable = new Headers(target);
|
|
284
|
+
return _mutable[prop](...args);
|
|
285
|
+
};
|
|
286
|
+
const value = Reflect.get(src, prop, src);
|
|
287
|
+
return typeof value === "function" ? value.bind(src) : value;
|
|
288
|
+
} });
|
|
289
|
+
let _cookies = null;
|
|
290
|
+
function getCookies() {
|
|
291
|
+
if (_cookies) return _cookies;
|
|
292
|
+
_cookies = parseCookieHeader(headersProxy.get("cookie") || "");
|
|
293
|
+
return _cookies;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
headers: headersProxy,
|
|
297
|
+
get cookies() {
|
|
298
|
+
return getCookies();
|
|
299
|
+
}
|
|
300
|
+
};
|
|
392
301
|
}
|
|
393
|
-
// ---------------------------------------------------------------------------
|
|
394
|
-
// Public API
|
|
395
|
-
// ---------------------------------------------------------------------------
|
|
396
302
|
/**
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (state.headersContext.accessError) {
|
|
414
|
-
return _decorateRejectedRequestApiPromise(state.headersContext.accessError);
|
|
415
|
-
}
|
|
416
|
-
markDynamicUsage();
|
|
417
|
-
const readonlyHeaders = _getReadonlyHeaders(state.headersContext);
|
|
418
|
-
return _decorateRequestApiPromise(Promise.resolve(readonlyHeaders), readonlyHeaders);
|
|
303
|
+
* Read-only Headers instance from the incoming request.
|
|
304
|
+
* Returns a Promise in Next.js 15+ style (but resolves synchronously since
|
|
305
|
+
* the context is already available).
|
|
306
|
+
*/
|
|
307
|
+
function headers() {
|
|
308
|
+
try {
|
|
309
|
+
throwIfInsideCacheScope("headers()");
|
|
310
|
+
} catch (error) {
|
|
311
|
+
return _decorateRejectedRequestApiPromise(error);
|
|
312
|
+
}
|
|
313
|
+
const state = _getState();
|
|
314
|
+
if (!state.headersContext) return _decorateRejectedRequestApiPromise(/* @__PURE__ */ new Error("headers() can only be called from a Server Component, Route Handler, or Server Action. Make sure you're not calling it from a Client Component."));
|
|
315
|
+
if (state.headersContext.accessError) return _decorateRejectedRequestApiPromise(state.headersContext.accessError);
|
|
316
|
+
markDynamicUsage();
|
|
317
|
+
const readonlyHeaders = _getReadonlyHeaders(state.headersContext);
|
|
318
|
+
return _decorateRequestApiPromise(Promise.resolve(readonlyHeaders), readonlyHeaders);
|
|
419
319
|
}
|
|
420
320
|
/**
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return _decorateRejectedRequestApiPromise(state.headersContext.accessError);
|
|
437
|
-
}
|
|
438
|
-
markDynamicUsage();
|
|
439
|
-
const cookieStore = _areCookiesMutableInCurrentPhase()
|
|
440
|
-
? _getMutableCookies(state.headersContext)
|
|
441
|
-
: _getReadonlyCookies(state.headersContext);
|
|
442
|
-
return _decorateRequestApiPromise(Promise.resolve(cookieStore), cookieStore);
|
|
321
|
+
* Cookie jar from the incoming request.
|
|
322
|
+
* Returns a ReadonlyRequestCookies-like object.
|
|
323
|
+
*/
|
|
324
|
+
function cookies() {
|
|
325
|
+
try {
|
|
326
|
+
throwIfInsideCacheScope("cookies()");
|
|
327
|
+
} catch (error) {
|
|
328
|
+
return _decorateRejectedRequestApiPromise(error);
|
|
329
|
+
}
|
|
330
|
+
const state = _getState();
|
|
331
|
+
if (!state.headersContext) return _decorateRejectedRequestApiPromise(/* @__PURE__ */ new Error("cookies() can only be called from a Server Component, Route Handler, or Server Action."));
|
|
332
|
+
if (state.headersContext.accessError) return _decorateRejectedRequestApiPromise(state.headersContext.accessError);
|
|
333
|
+
markDynamicUsage();
|
|
334
|
+
const cookieStore = _areCookiesMutableInCurrentPhase() ? _getMutableCookies(state.headersContext) : _getReadonlyCookies(state.headersContext);
|
|
335
|
+
return _decorateRequestApiPromise(Promise.resolve(cookieStore), cookieStore);
|
|
443
336
|
}
|
|
444
|
-
// ---------------------------------------------------------------------------
|
|
445
|
-
// Writable cookie accumulator for Route Handlers / Server Actions
|
|
446
|
-
// ---------------------------------------------------------------------------
|
|
447
337
|
/** Accumulated Set-Cookie headers from cookies().set() / .delete() calls */
|
|
448
|
-
// (stored on _state)
|
|
449
338
|
/**
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
339
|
+
* Get and clear all pending Set-Cookie headers generated by cookies().set()/delete().
|
|
340
|
+
* Called by the framework after rendering to attach headers to the response.
|
|
341
|
+
*/
|
|
342
|
+
function getAndClearPendingCookies() {
|
|
343
|
+
const state = _getState();
|
|
344
|
+
const cookies = state.pendingSetCookies;
|
|
345
|
+
state.pendingSetCookies = [];
|
|
346
|
+
return cookies;
|
|
458
347
|
}
|
|
459
|
-
// Draft mode cookie name (matches Next.js convention)
|
|
460
348
|
const DRAFT_MODE_COOKIE = "__prerender_bypass";
|
|
461
|
-
// Draft mode secret — generated once at build time via Vite `define` so the
|
|
462
|
-
// __prerender_bypass cookie is consistent across all server instances (e.g.
|
|
463
|
-
// multiple Cloudflare Workers isolates).
|
|
464
349
|
function getDraftSecret() {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
"This should be set by the Vite plugin at build time.");
|
|
469
|
-
}
|
|
470
|
-
return secret;
|
|
350
|
+
const secret = process.env.__VINEXT_DRAFT_SECRET;
|
|
351
|
+
if (!secret) throw new Error("[vinext] __VINEXT_DRAFT_SECRET is not defined. This should be set by the Vite plugin at build time.");
|
|
352
|
+
return secret;
|
|
471
353
|
}
|
|
472
|
-
// Store for Set-Cookie headers generated by draftMode().enable()/disable()
|
|
473
|
-
// (stored on _state)
|
|
474
354
|
/**
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
355
|
+
* Get any Set-Cookie header generated by draftMode().enable()/disable().
|
|
356
|
+
* Called by the framework after rendering to attach the header to the response.
|
|
357
|
+
*/
|
|
358
|
+
function getDraftModeCookieHeader() {
|
|
359
|
+
const state = _getState();
|
|
360
|
+
const header = state.draftModeCookieHeader;
|
|
361
|
+
state.draftModeCookieHeader = null;
|
|
362
|
+
return header;
|
|
483
363
|
}
|
|
484
364
|
/**
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
const secure = typeof process !== "undefined" && process.env?.NODE_ENV === "production" ? "; Secure" : "";
|
|
512
|
-
state.draftModeCookieHeader = `${DRAFT_MODE_COOKIE}=${secret}; Path=/; HttpOnly; SameSite=Lax${secure}`;
|
|
513
|
-
},
|
|
514
|
-
disable() {
|
|
515
|
-
if (state.headersContext?.accessError) {
|
|
516
|
-
throw state.headersContext.accessError;
|
|
517
|
-
}
|
|
518
|
-
if (state.headersContext) {
|
|
519
|
-
state.headersContext.cookies.delete(DRAFT_MODE_COOKIE);
|
|
520
|
-
}
|
|
521
|
-
const secure = typeof process !== "undefined" && process.env?.NODE_ENV === "production" ? "; Secure" : "";
|
|
522
|
-
state.draftModeCookieHeader = `${DRAFT_MODE_COOKIE}=; Path=/; HttpOnly; SameSite=Lax${secure}; Max-Age=0`;
|
|
523
|
-
},
|
|
524
|
-
};
|
|
365
|
+
* Draft mode — check/toggle via a `__prerender_bypass` cookie.
|
|
366
|
+
*
|
|
367
|
+
* - `isEnabled`: true if the bypass cookie is present in the request
|
|
368
|
+
* - `enable()`: sets the bypass cookie (for Route Handlers)
|
|
369
|
+
* - `disable()`: clears the bypass cookie
|
|
370
|
+
*/
|
|
371
|
+
async function draftMode() {
|
|
372
|
+
throwIfInsideCacheScope("draftMode()");
|
|
373
|
+
const state = _getState();
|
|
374
|
+
if (state.headersContext?.accessError) throw state.headersContext.accessError;
|
|
375
|
+
markDynamicUsage();
|
|
376
|
+
const secret = getDraftSecret();
|
|
377
|
+
return {
|
|
378
|
+
isEnabled: state.headersContext ? state.headersContext.cookies.get(DRAFT_MODE_COOKIE) === secret : false,
|
|
379
|
+
enable() {
|
|
380
|
+
if (state.headersContext?.accessError) throw state.headersContext.accessError;
|
|
381
|
+
if (state.headersContext) state.headersContext.cookies.set(DRAFT_MODE_COOKIE, secret);
|
|
382
|
+
state.draftModeCookieHeader = `${DRAFT_MODE_COOKIE}=${secret}; Path=/; HttpOnly; SameSite=Lax${typeof process !== "undefined" && process.env?.NODE_ENV === "production" ? "; Secure" : ""}`;
|
|
383
|
+
},
|
|
384
|
+
disable() {
|
|
385
|
+
if (state.headersContext?.accessError) throw state.headersContext.accessError;
|
|
386
|
+
if (state.headersContext) state.headersContext.cookies.delete(DRAFT_MODE_COOKIE);
|
|
387
|
+
state.draftModeCookieHeader = `${DRAFT_MODE_COOKIE}=; Path=/; HttpOnly; SameSite=Lax${typeof process !== "undefined" && process.env?.NODE_ENV === "production" ? "; Secure" : ""}; Max-Age=0`;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
525
390
|
}
|
|
526
|
-
// ---------------------------------------------------------------------------
|
|
527
|
-
// Cookie name/value validation (RFC 6265)
|
|
528
|
-
// ---------------------------------------------------------------------------
|
|
529
391
|
/**
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
392
|
+
* RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).
|
|
393
|
+
* Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\"/[]?={}
|
|
394
|
+
*/
|
|
533
395
|
const VALID_COOKIE_NAME_RE = /^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/;
|
|
534
396
|
function validateCookieName(name) {
|
|
535
|
-
|
|
536
|
-
throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);
|
|
537
|
-
}
|
|
397
|
+
if (!name || !VALID_COOKIE_NAME_RE.test(name)) throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);
|
|
538
398
|
}
|
|
539
399
|
/**
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
400
|
+
* Validate cookie attribute values (path, domain) to prevent injection
|
|
401
|
+
* via semicolons, newlines, or other control characters.
|
|
402
|
+
*/
|
|
543
403
|
function validateCookieAttributeValue(value, attributeName) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
404
|
+
for (let i = 0; i < value.length; i++) {
|
|
405
|
+
const code = value.charCodeAt(i);
|
|
406
|
+
if (code <= 31 || code === 127 || value[i] === ";") throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
var RequestCookies = class {
|
|
410
|
+
_cookies;
|
|
411
|
+
constructor(cookies) {
|
|
412
|
+
this._cookies = cookies;
|
|
413
|
+
}
|
|
414
|
+
get(name) {
|
|
415
|
+
const value = this._cookies.get(name);
|
|
416
|
+
if (value === void 0) return void 0;
|
|
417
|
+
return {
|
|
418
|
+
name,
|
|
419
|
+
value
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
getAll(nameOrOptions) {
|
|
423
|
+
const name = typeof nameOrOptions === "string" ? nameOrOptions : nameOrOptions?.name;
|
|
424
|
+
const result = [];
|
|
425
|
+
for (const [cookieName, value] of this._cookies) if (name === void 0 || cookieName === name) result.push({
|
|
426
|
+
name: cookieName,
|
|
427
|
+
value
|
|
428
|
+
});
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
has(name) {
|
|
432
|
+
return this._cookies.has(name);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Set a cookie. In Route Handlers and Server Actions, this produces
|
|
436
|
+
* a Set-Cookie header on the response.
|
|
437
|
+
*/
|
|
438
|
+
set(nameOrOptions, value, options) {
|
|
439
|
+
let cookieName;
|
|
440
|
+
let cookieValue;
|
|
441
|
+
let opts;
|
|
442
|
+
if (typeof nameOrOptions === "string") {
|
|
443
|
+
cookieName = nameOrOptions;
|
|
444
|
+
cookieValue = value ?? "";
|
|
445
|
+
opts = options;
|
|
446
|
+
} else {
|
|
447
|
+
cookieName = nameOrOptions.name;
|
|
448
|
+
cookieValue = nameOrOptions.value;
|
|
449
|
+
opts = nameOrOptions;
|
|
450
|
+
}
|
|
451
|
+
validateCookieName(cookieName);
|
|
452
|
+
this._cookies.set(cookieName, cookieValue);
|
|
453
|
+
const parts = [`${cookieName}=${encodeURIComponent(cookieValue)}`];
|
|
454
|
+
const path = opts?.path ?? "/";
|
|
455
|
+
validateCookieAttributeValue(path, "Path");
|
|
456
|
+
parts.push(`Path=${path}`);
|
|
457
|
+
if (opts?.domain) {
|
|
458
|
+
validateCookieAttributeValue(opts.domain, "Domain");
|
|
459
|
+
parts.push(`Domain=${opts.domain}`);
|
|
460
|
+
}
|
|
461
|
+
if (opts?.maxAge !== void 0) parts.push(`Max-Age=${opts.maxAge}`);
|
|
462
|
+
if (opts?.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);
|
|
463
|
+
if (opts?.httpOnly) parts.push("HttpOnly");
|
|
464
|
+
if (opts?.secure) parts.push("Secure");
|
|
465
|
+
if (opts?.sameSite) parts.push(`SameSite=${opts.sameSite}`);
|
|
466
|
+
_getState().pendingSetCookies.push(parts.join("; "));
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Delete a cookie by emitting an expired Set-Cookie header.
|
|
471
|
+
*/
|
|
472
|
+
delete(nameOrOptions) {
|
|
473
|
+
const name = typeof nameOrOptions === "string" ? nameOrOptions : nameOrOptions.name;
|
|
474
|
+
const path = typeof nameOrOptions === "string" ? "/" : nameOrOptions.path ?? "/";
|
|
475
|
+
const domain = typeof nameOrOptions === "string" ? void 0 : nameOrOptions.domain;
|
|
476
|
+
validateCookieName(name);
|
|
477
|
+
validateCookieAttributeValue(path, "Path");
|
|
478
|
+
if (domain) validateCookieAttributeValue(domain, "Domain");
|
|
479
|
+
this._cookies.delete(name);
|
|
480
|
+
const parts = [`${name}=`, `Path=${path}`];
|
|
481
|
+
if (domain) parts.push(`Domain=${domain}`);
|
|
482
|
+
parts.push(`Expires=${EXPIRED_COOKIE_DATE}`);
|
|
483
|
+
_getState().pendingSetCookies.push(parts.join("; "));
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
get size() {
|
|
487
|
+
return this._cookies.size;
|
|
488
|
+
}
|
|
489
|
+
[Symbol.iterator]() {
|
|
490
|
+
const entries = this._cookies.entries();
|
|
491
|
+
const iter = {
|
|
492
|
+
[Symbol.iterator]() {
|
|
493
|
+
return iter;
|
|
494
|
+
},
|
|
495
|
+
next() {
|
|
496
|
+
const { value, done } = entries.next();
|
|
497
|
+
if (done) return {
|
|
498
|
+
value: void 0,
|
|
499
|
+
done: true
|
|
500
|
+
};
|
|
501
|
+
const [name, val] = value;
|
|
502
|
+
return {
|
|
503
|
+
value: [name, {
|
|
504
|
+
name,
|
|
505
|
+
value: val
|
|
506
|
+
}],
|
|
507
|
+
done: false
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
return iter;
|
|
512
|
+
}
|
|
513
|
+
toString() {
|
|
514
|
+
const parts = [];
|
|
515
|
+
for (const [name, value] of this._cookies) parts.push(`${name}=${value}`);
|
|
516
|
+
return parts.join("; ");
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
//#endregion
|
|
520
|
+
export { applyMiddlewareRequestHeaders, consumeDynamicUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersContext, headers, headersContextFromRequest, markDynamicUsage, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, throwIfInsideCacheScope };
|
|
521
|
+
|
|
658
522
|
//# sourceMappingURL=headers.js.map
|