mirror of https://github.com/lukechilds/node.git
2 changed files with 135 additions and 0 deletions
@ -0,0 +1,63 @@ |
|||||
|
var common = require('../common'); |
||||
|
var assert = require('assert'); |
||||
|
var http = require('http'); |
||||
|
|
||||
|
var reqEndCount = 0; |
||||
|
|
||||
|
var server = http.Server(function(req, res) { |
||||
|
res.writeHead(200); |
||||
|
res.end("hello world\n"); |
||||
|
|
||||
|
var buffer = ''; |
||||
|
|
||||
|
req.setEncoding('utf8'); |
||||
|
|
||||
|
req.on('data', function(s) { |
||||
|
buffer += s; |
||||
|
}); |
||||
|
|
||||
|
req.on('end', function() { |
||||
|
reqEndCount++; |
||||
|
assert.equal(body, buffer); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
var responses = 0; |
||||
|
var N = 10; |
||||
|
var M = 10; |
||||
|
|
||||
|
var body = '' |
||||
|
for (var i = 0; i < 1000; i++) { |
||||
|
body += 'hello world'; |
||||
|
} |
||||
|
|
||||
|
var options = { |
||||
|
port: common.PORT, |
||||
|
path: '/', |
||||
|
method: 'PUT' |
||||
|
}; |
||||
|
|
||||
|
server.listen(common.PORT, function() { |
||||
|
for (var i = 0; i < N; i++) { |
||||
|
setTimeout(function () { |
||||
|
for (var j = 0; j < M; j++) { |
||||
|
|
||||
|
var req = http.request(options, function(res) { |
||||
|
console.log(res.statusCode); |
||||
|
if (++responses == N * M) server.close(); |
||||
|
}).on('error', function(e) { |
||||
|
console.log(e.message); |
||||
|
process.exit(1); |
||||
|
}); |
||||
|
|
||||
|
req.end(body); |
||||
|
} |
||||
|
}, i); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
process.on('exit', function() { |
||||
|
assert.equal(N * M, responses); |
||||
|
assert.equal(N * M, reqEndCount); |
||||
|
}); |
@ -0,0 +1,72 @@ |
|||||
|
// I hate HTTP. One way of terminating an HTTP response is to not send
|
||||
|
// a content-length header, not send a transfer-encoding: chunked header,
|
||||
|
// and simply terminate the TCP connection. That is identity
|
||||
|
// transfer-encoding.
|
||||
|
//
|
||||
|
// This test is to be sure that the https client is handling this case
|
||||
|
// correctly.
|
||||
|
if (!process.versions.openssl) { |
||||
|
console.error('Skipping because node compiled without OpenSSL.'); |
||||
|
process.exit(0); |
||||
|
} |
||||
|
|
||||
|
var common = require('../common'); |
||||
|
var assert = require('assert'); |
||||
|
var net = require('net'); |
||||
|
var http = require('http'); |
||||
|
var fs = require('fs'); |
||||
|
|
||||
|
|
||||
|
var server = net.Server(function(socket) { |
||||
|
console.log('2) Server got request'); |
||||
|
socket.write('HTTP/1.1 200 OK\r\n' + |
||||
|
'Content-Length: 200\r\n'); |
||||
|
|
||||
|
// note headers are incomplete.
|
||||
|
|
||||
|
setTimeout(function() { |
||||
|
socket.end('Server: gws\r\n'); |
||||
|
console.log('4) Server finished response'); |
||||
|
}, 100); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
var gotHeaders = false; |
||||
|
var gotEnd = false; |
||||
|
var bodyBuffer = ''; |
||||
|
|
||||
|
server.listen(common.PORT, function() { |
||||
|
console.log('1) Making Request'); |
||||
|
var req = http.get({ port: common.PORT }, function(res) { |
||||
|
server.close(); |
||||
|
console.log('3) Client got response headers.'); |
||||
|
|
||||
|
assert.equal('gws', res.headers.server); |
||||
|
gotHeaders = true; |
||||
|
|
||||
|
res.setEncoding('utf8'); |
||||
|
res.on('data', function(s) { |
||||
|
bodyBuffer += s; |
||||
|
}); |
||||
|
|
||||
|
res.on('aborted', function() { |
||||
|
console.log('RESPONSE ABORTED'); |
||||
|
}); |
||||
|
|
||||
|
req.connection.on('error', function() { |
||||
|
console.log('INCOMOLETE'); |
||||
|
}); |
||||
|
|
||||
|
res.on('end', function() { |
||||
|
console.log('5) Client got "end" event.'); |
||||
|
gotEnd = true; |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
process.on('exit', function() { |
||||
|
assert.ok(gotHeaders); |
||||
|
assert.ok(gotEnd); |
||||
|
assert.equal('hello\nworld\n', bodyBuffer); |
||||
|
}); |
||||
|
|
Loading…
Reference in new issue