Skip to content

Commit

Permalink
Added test to illustrate request#321
Browse files Browse the repository at this point in the history
  • Loading branch information
alexindigo committed Sep 12, 2012
1 parent 0d98e5b commit 48c9881
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/run.js
Expand Up @@ -21,16 +21,17 @@ var tests = [
, 'test-pool.js'
, 'test-protocol-changing-redirect.js'
, 'test-proxy.js'
, 'test-piped-redirect.js'
, 'test-qs.js'
, 'test-redirect.js'
, 'test-timeout.js'
, 'test-toJSON.js'
, 'test-tunnel.js'
]
]

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

var file = tests.shift()
console.log(file)
var proc = spawn('node', [ 'tests/' + file ])
Expand Down
52 changes: 52 additions & 0 deletions tests/test-piped-redirect.js
@@ -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;

});

0 comments on commit 48c9881

Please sign in to comment.