Skip to content

Commit 9a87002

Browse files
committed
Add test case for redirect without "url" option
1 parent c4121d1 commit 9a87002

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

test/redirect.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,35 @@ test('redirect should clear explicitly specified `Host` (note uppercase) header'
326326
})
327327
})
328328
})
329+
330+
test('follow redirects without "url" option', function (t) {
331+
t.plan(15)
332+
333+
let num = 0
334+
const server = http.createServer(function (req, res) {
335+
t.equal(req.url, '/' + num, 'visited /' + num)
336+
337+
if (num < 10) {
338+
num += 1
339+
res.statusCode = 301
340+
res.setHeader('Location', '/' + num)
341+
res.end()
342+
} else {
343+
res.statusCode = 200
344+
res.end('response')
345+
}
346+
})
347+
348+
server.listen(0, function () {
349+
const port = server.address().port
350+
get({ hostname: 'localhost', port, path: '/0' }, function (err, res) {
351+
t.error(err)
352+
t.equal(res.statusCode, 200)
353+
concat(res, function (err, data) {
354+
t.error(err)
355+
t.equal(data.toString(), 'response')
356+
server.close()
357+
})
358+
})
359+
})
360+
})

0 commit comments

Comments
 (0)