Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: response.url after redirect is set to target url #2716

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/fetch/fetch-url-after-redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict'

const assert = require('node:assert')
const { test } = require('node:test')
const { createServer } = require('node:http')
const { fetch } = require('../..')
const { closeServerAsPromise } = require('../utils/node-http')
const { promisify } = require('node:util')

test('after redirecting the url of the response is set to the target url', async (t) => {
// redirect-1 -> redirect-2 -> target
const server = createServer((req, res) => {
switch (res.req.url) {
case '/redirect-1':
res.writeHead(302, undefined, { Location: '/redirect-2' })
res.end()
break
case '/redirect-2':
res.writeHead(302, undefined, { Location: '/redirect-3' })
res.end()
break
case '/redirect-3':
res.writeHead(302, undefined, { Location: '/target' })
res.end()
break
case '/target':
res.writeHead(200, 'dummy', { 'Content-Type': 'text/plain' })
res.end()
break
}
})
t.after(closeServerAsPromise(server))

const listenAsync = promisify(server.listen.bind(server))
await listenAsync(0)
const { port } = server.address()
const response = await fetch(`http://127.0.0.1:${port}/redirect-1`)

assert.strictEqual(response.url, `http://127.0.0.1:${port}/target`)
})
Loading