diff options
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) +}) |