Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix + test for piped into request bumped into redirect. #321 #322

Merged
merged 2 commits into from
Sep 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ Request.prototype.start = function () {
) )
if (self.followAllRedirects) self.method = 'GET' if (self.followAllRedirects) self.method = 'GET'
// self.method = 'GET'; // Force all redirects to use GET || commented out fixes #215 // self.method = 'GET'; // Force all redirects to use GET || commented out fixes #215
delete self.src
delete self.req delete self.req
delete self.agent delete self.agent
delete self._started delete self._started
Expand Down
5 changes: 3 additions & 2 deletions tests/run.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ var tests = [
, 'test-pool.js' , 'test-pool.js'
, 'test-protocol-changing-redirect.js' , 'test-protocol-changing-redirect.js'
, 'test-proxy.js' , 'test-proxy.js'
, 'test-piped-redirect.js'
, 'test-qs.js' , 'test-qs.js'
, 'test-redirect.js' , 'test-redirect.js'
, 'test-timeout.js' , 'test-timeout.js'
, 'test-toJSON.js' , 'test-toJSON.js'
, 'test-tunnel.js' , 'test-tunnel.js'
] ]


var next = function () { var next = function () {
if (tests.length === 0) process.exit(exitCode); if (tests.length === 0) process.exit(exitCode);

var file = tests.shift() var file = tests.shift()
console.log(file) console.log(file)
var proc = spawn('node', [ 'tests/' + file ]) var proc = spawn('node', [ 'tests/' + file ])
Expand Down
52 changes: 52 additions & 0 deletions tests/test-piped-redirect.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,52 @@
var http = require('http')
, assert = require('assert')
, request = require('../main.js')
;

var portOne = 8968
, portTwo = 8969
;


// server one
var s1 = http.createServer(function (req, resp)
{
if (req.url == '/original')
{
resp.writeHeader(302, {'location': '/redirected'})
resp.end()
}
else if (req.url == '/redirected')
{
resp.writeHeader(200, {'content-type': 'text/plain'})
resp.write('OK')
resp.end()
}

}).listen(portOne);


// server two
var s2 = http.createServer(function (req, resp)
{

var x = request('http://localhost:'+portOne+'/original')
req.pipe(x)
x.pipe(resp)

}).listen(portTwo, function()
{

var r = request('http://localhost:'+portTwo+'/original', function (err, res, body) {

assert.equal(body, 'OK')

s1.close()
s2.close()

});

// it hangs, so wait a second :)
r.timeout = 1000;

});