Skip to content

Commit 8ff1932

Browse files
authored
Merge branch 'main' into middleware-cookies-internal-header
2 parents d2d41fa + 5489c0d commit 8ff1932

File tree

18 files changed

+1116
-302
lines changed

18 files changed

+1116
-302
lines changed

.github/workflows/run-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
node-version: '18.x'
5959
cache: 'npm'
6060
cache-dependency-path: '**/package-lock.json'
61-
- uses: oven-sh/setup-bun@v1
61+
- uses: oven-sh/setup-bun@v2
6262
- name: setup pnpm/yarn
6363
run: |
6464
npm install -g corepack
@@ -114,13 +114,18 @@ jobs:
114114

115115
test:
116116
needs: setup
117-
runs-on: ${{ matrix.os }}
118117
strategy:
119118
fail-fast: false
120119
matrix:
121120
shard: [1, 2, 3, 4, 5, 6, 7, 8]
122121
os: [ubuntu-latest, windows-latest]
123122
version: ${{ fromJson(needs.setup.outputs.matrix) }}
123+
exclude:
124+
- os: windows-latest
125+
version: '13.5.1'
126+
- os: windows-latest
127+
version: '14.2.15'
128+
runs-on: ${{ matrix.os }}
124129
steps:
125130
- uses: actions/checkout@v4
126131
- name: 'Install Node'

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "5.10.7"
2+
".": "5.11.1"
33
}

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Changelog
22

3+
## [5.11.1](https://github.com/opennextjs/opennextjs-netlify/compare/v5.11.0...v5.11.1) (2025-05-06)
4+
5+
6+
### Bug Fixes
7+
8+
* **edge-runtime:** match path with URI-encoded chars ([#2873](https://github.com/opennextjs/opennextjs-netlify/issues/2873)) ([7fe6b3b](https://github.com/opennextjs/opennextjs-netlify/commit/7fe6b3b634322de47d06110e952a5b67bc8e1d1c))
9+
10+
## [5.11.0](https://github.com/opennextjs/opennextjs-netlify/compare/v5.10.7...v5.11.0) (2025-05-05)
11+
12+
13+
### Features
14+
15+
* support 'use cache' ([#2862](https://github.com/opennextjs/opennextjs-netlify/issues/2862)) ([2810004](https://github.com/opennextjs/opennextjs-netlify/commit/2810004a2cbeeb738cbe7cf70f2b8bd2bbea6156))
16+
17+
18+
### Bug Fixes
19+
20+
* add a fallback for loadManifest import path ([#2881](https://github.com/opennextjs/opennextjs-netlify/issues/2881)) ([a9119d3](https://github.com/opennextjs/opennextjs-netlify/commit/a9119d3574e30dd61b22ab80f273f12ed7f2982f))
21+
* remove unused OTel tracing setup ([#2874](https://github.com/opennextjs/opennextjs-netlify/issues/2874)) ([a220a30](https://github.com/opennextjs/opennextjs-netlify/commit/a220a30fa3d5ff14b6059963630825c8b3dd1005))
22+
323
## [5.10.7](https://github.com/opennextjs/opennextjs-netlify/compare/v5.10.6...v5.10.7) (2025-04-18)
424

525

e2e-report/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e-report/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@netlify/plugin-nextjs": "^5.10.7",
12+
"@netlify/plugin-nextjs": "^5.11.1",
1313
"next": "^14.2.26",
1414
"react": "^18.3.1",
1515
"react-dom": "^18.3.1"

edge-runtime/lib/response.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,13 @@ export const buildResponse = async ({
163163

164164
if (rewriteUrl.origin !== baseUrl.origin) {
165165
logger.withFields({ rewrite_url: rewrite }).debug('Rewriting to external url')
166-
let proxyRequest: Request
166+
const proxyRequest = await cloneRequest(rewriteUrl, request)
167167

168168
// Remove Netlify internal headers
169-
const headers = new Headers(
170-
[...request.headers.entries()].filter(([key]) => !key.startsWith('x-nf-')),
171-
)
172-
if (request.body && !request.bodyUsed) {
173-
// This is not ideal, but streaming to an external URL doesn't work
174-
const body = await request.arrayBuffer()
175-
proxyRequest = new Request(rewriteUrl, {
176-
headers,
177-
method: request.method,
178-
body,
179-
})
180-
} else {
181-
proxyRequest = new Request(rewriteUrl, {
182-
headers,
183-
method: request.method,
184-
})
169+
for (const key of request.headers.keys()) {
170+
if (key.startsWith('x-nf-')) {
171+
proxyRequest.headers.delete(key)
172+
}
185173
}
186174

187175
return addMiddlewareHeaders(fetch(proxyRequest, { redirect: 'manual' }), edgeResponse)
@@ -207,7 +195,7 @@ export const buildResponse = async ({
207195
request.headers.set('x-middleware-rewrite', target)
208196

209197
// coookies set in middleware need to be available during the lambda request
210-
const newRequest = new Request(target, request)
198+
const newRequest = await cloneRequest(target, request)
211199
const newRequestCookies = mergeMiddlewareCookies(edgeResponse, newRequest)
212200
if (newRequestCookies) {
213201
newRequest.headers.set('Cookie', newRequestCookies)
@@ -241,7 +229,7 @@ export const buildResponse = async ({
241229
edgeResponse.headers.delete('x-middleware-next')
242230

243231
// coookies set in middleware need to be available during the lambda request
244-
const newRequest = new Request(request)
232+
const newRequest = await cloneRequest(request.url, request)
245233
const newRequestCookies = mergeMiddlewareCookies(edgeResponse, newRequest)
246234
if (newRequestCookies) {
247235
newRequest.headers.set('Cookie', newRequestCookies)
@@ -284,3 +272,13 @@ function normalizeLocalizedTarget({
284272
}
285273
return targetUrl.toString()
286274
}
275+
276+
async function cloneRequest(url, request: Request) {
277+
// This is not ideal, but streaming to an external URL doesn't work
278+
const body = request.body && !request.bodyUsed ? await request.arrayBuffer() : undefined
279+
return new Request(url, {
280+
headers: request.headers,
281+
method: request.method,
282+
body,
283+
})
284+
}

edge-runtime/lib/routing.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,24 @@ export interface MiddlewareMatcher {
424424
missing?: RouteHas[]
425425
}
426426

427+
const decodeMaybeEncodedPath = (path: string): string => {
428+
try {
429+
return decodeURIComponent(path)
430+
} catch {
431+
return path
432+
}
433+
}
434+
427435
export function getMiddlewareRouteMatcher(matchers: MiddlewareMatcher[]): MiddlewareRouteMatch {
428436
return (
429-
pathname: string | null | undefined,
437+
unsafePathname: string | null | undefined,
430438
req: Pick<Request, 'headers' | 'url'>,
431439
query: Params,
432440
) => {
441+
const pathname = decodeMaybeEncodedPath(unsafePathname ?? '')
442+
433443
for (const matcher of matchers) {
434-
const routeMatch = new RegExp(matcher.regexp).exec(pathname!)
444+
const routeMatch = new RegExp(matcher.regexp).exec(pathname)
435445
if (!routeMatch) {
436446
continue
437447
}

0 commit comments

Comments
 (0)