request
gets redirects by default, it can get through 10 redirects by default. You can check this in the docs. Downside of this is that you would not know if url you get is a redirected one or original one by default options.
For example:
request('http://www.google.com', function (error, response, body) {
console.log(response.headers)
console.log(body) // Print the google web page.
})
gives output
> { date: 'Wed, 22 May 2013 15:11:58 GMT',
expires: '-1',
'cache-control': 'private, max-age=0',
'content-type': 'text/html; charset=ISO-8859-1',
server: 'gws',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'SAMEORIGIN',
'transfer-encoding': 'chunked' }
but if you give option followRedirect
as false
request({url:'http://www.google.com',followRedirect :false}, function (error, response, body) {
console.log(response.headers)
console.log(body)
});
it gives
> { location: 'http://www.google.co.in/',
'cache-control': 'private',
'content-type': 'text/html; charset=UTF-8',
date: 'Wed, 22 May 2013 15:12:27 GMT',
server: 'gws',
'content-length': '221',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'SAMEORIGIN' }
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.in/">here</A>.
</BODY></HTML>
So don't worry about getting the redirected content. But if you want to know if it is redirected or not set followRedirect
false and check the location
header in the response.