Skip to content

Commit

Permalink
Added a failing test case where the response changes size.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Jan 15, 2014
1 parent 8f5e517 commit 9fee09f
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ var req = http.request(options, function(res) {

assert.equal('<html><head></head><body><div class="a">Nodejitsu Http Proxy</div><div>+ Trumpet</div></body></html>', out);
console.log("# Content Returned Correct");
process.exit(0);
});

res.on('close', function(){
Expand All @@ -96,3 +95,39 @@ req.on('close', function(){
req.write('<html><head></head><body><div class="a">Nodejitsu Http Proxy</div><div class="b">&amp; Frames</div></body></html>');
req.end();

test('Streams can change the response size', function (t) {
t.plan(1);

http.createServer(function (req, res) {
s = '<body><p>hi</p></body>';
res.setHeader('Content-length', '' + s.length); // All ASCII today
res.end(s);
}).listen(9001);

var sizeChanger = {
query: 'p',
func: function (elem) {
ws = elem.createWriteStream({outer: true})
ws.end('<p>A larger paragraph</p>');
}
};
httpProxy.createServer(
require('../')(null, [sizeChanger]),
9001, 'localhost'
).listen(8001);

http.get('http://localhost:8001', function (res) {
var str = ''; // yeah well it's all ASCII today.
res.on('data', function (data) {
str += data;
console.log("'data'", '' + data);
});
res.on('end', function () {
t.equal(str, '<body><p>A larger paragraph</p></body>');
t.end();
});
});
});



0 comments on commit 9fee09f

Please sign in to comment.