Skip to content

Commit

Permalink
Add test with nested subrequests
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Dec 2, 2021
1 parent e5eb12c commit 023df59
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
@@ -0,0 +1,7 @@
import { NextResponse } from 'next/server'

export function middleware() {
const response = NextResponse.next()
response.headers.set('x-dynamic-path', 'true')
return response
}
Expand Up @@ -54,9 +54,7 @@ export async function middleware(request) {
}

if (url.pathname.endsWith('/root-subrequest')) {
return fetch(
`http://${request.headers.get('host')}/interface/root-subrequest`
)
return fetch(url)
}

return new Response(null, {
Expand Down
Expand Up @@ -57,11 +57,11 @@ export async function middleware(request, ev) {
ev.waitUntil(
(async () => {
writer.write(encoder.encode('this is a streamed '.repeat(10)))
await sleep(2000)
await sleep(200)
writer.write(encoder.encode('after 2 seconds '.repeat(10)))
await sleep(2000)
await sleep(200)
writer.write(encoder.encode('after 4 seconds '.repeat(10)))
await sleep(2000)
await sleep(200)
writer.close()
})()
)
Expand Down
8 changes: 8 additions & 0 deletions test/integration/middleware/core/test/index.test.js
Expand Up @@ -447,6 +447,14 @@ function interfaceTests(locale = '') {
const element = await browser.elementByCss('.title')
expect(await element.text()).toEqual('Dynamic route')
})

it(`${locale} allows subrequests without infinite loops`, async () => {
const res = await fetchViaHTTP(
context.appPort,
`/interface/root-subrequest`
)
expect(res.headers.get('x-dynamic-path')).toBe('true')
})
}

function getCookieFromResponse(res, cookieName) {
Expand Down

0 comments on commit 023df59

Please sign in to comment.