node/test/sequential/test-zerolengthbufferbug.js

37 lines
792 B
JavaScript
Raw Normal View History

// Serving up a zero-length buffer should work.
2010-12-03 09:03:18 +08:00
var common = require('../common');
var assert = require('assert');
var http = require('http');
2010-12-03 09:03:18 +08:00
var server = http.createServer(function(req, res) {
var buffer = new Buffer(0);
2010-12-03 09:03:18 +08:00
// FIXME: WTF gjslint want this?
res.writeHead(200, {'Content-Type': 'text/html',
2010-12-03 09:03:18 +08:00
'Content-Length': buffer.length});
res.end(buffer);
});
var gotResponse = false;
var resBodySize = 0;
2010-12-03 09:03:18 +08:00
server.listen(common.PORT, function() {
http.get({ port: common.PORT }, function(res) {
gotResponse = true;
2010-12-03 09:03:18 +08:00
res.on('data', function(d) {
resBodySize += d.length;
});
2010-12-03 09:03:18 +08:00
res.on('end', function(d) {
server.close();
});
});
});
2010-12-03 09:03:18 +08:00
process.on('exit', function() {
assert.ok(gotResponse);
assert.equal(0, resBodySize);
});