fix redirect and loop detection

add test using `nock` - request mocking lib