diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/redirect-pipeline.js | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/redirect-pipeline.js')
-rw-r--r-- | test/redirect-pipeline.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/redirect-pipeline.js b/test/redirect-pipeline.js new file mode 100644 index 0000000..e4be837 --- /dev/null +++ b/test/redirect-pipeline.js @@ -0,0 +1,50 @@ +'use strict' + +const t = require('tap') +const { pipeline: undiciPipeline } = require('..') +const { pipeline: streamPipelineCb } = require('stream') +const { promisify } = require('util') +const { createReadable, createWritable } = require('./utils/stream') +const { startRedirectingServer } = require('./utils/redirecting-servers') + +const streamPipeline = promisify(streamPipelineCb) + +t.test('should not follow redirection by default if not using RedirectAgent', async t => { + t.plan(3) + + const body = [] + const serverRoot = await startRedirectingServer(t) + + await streamPipeline( + createReadable('REQUEST'), + undiciPipeline(`http://${serverRoot}/`, {}, ({ statusCode, headers, body }) => { + t.equal(statusCode, 302) + t.equal(headers.location, `http://${serverRoot}/302/1`) + + return body + }), + createWritable(body) + ) + + t.equal(body.length, 0) +}) + +t.test('should not follow redirects when using RedirectAgent within pipeline', async t => { + t.plan(3) + + const body = [] + const serverRoot = await startRedirectingServer(t) + + await streamPipeline( + createReadable('REQUEST'), + undiciPipeline(`http://${serverRoot}/`, { maxRedirections: 1 }, ({ statusCode, headers, body }) => { + t.equal(statusCode, 302) + t.equal(headers.location, `http://${serverRoot}/302/1`) + + return body + }), + createWritable(body) + ) + + t.equal(body.length, 0) +}) |