Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed ugly response body bug

  • Loading branch information...
commit 3a10a605f79b1713133d0124876b6b10fe2de7cc 1 parent 5287bed
@dannycoates authored
View
1  .gitignore
@@ -1 +1,2 @@
.DS_Store
+node_modules
View
4 lib/endpoint.js
@@ -187,6 +187,7 @@ module.exports = function (inherits, EventEmitter) {
// this = request
function gotResponse(response) {
response.bodyChunks = []
+ response.bodyLength = 0
response.request = this
response.on('data', gotData)
response.on('end', gotEnd)
@@ -207,6 +208,7 @@ module.exports = function (inherits, EventEmitter) {
function gotData(chunk) {
this.request.lastTouched = clock
this.bodyChunks.push(chunk)
+ this.bodyLength += chunk.length
}
// this = response
@@ -218,7 +220,7 @@ module.exports = function (inherits, EventEmitter) {
if (req.callback === null) { return }
node.setHealthy(true)
- var buffer = new Buffer(this.bodyChunks.length)
+ var buffer = new Buffer(this.bodyLength)
var offset = 0
for (var i = 0; i < this.bodyChunks.length; i++) {
var chunk = this.bodyChunks[i]
View
6 package.json
@@ -1,6 +1,6 @@
{
"name": "poolee",
- "version": "0.1.0",
+ "version": "0.1.1",
"description": "HTTP pool and load balancer",
"homepage": "http://github.com/dannycoates/poolee",
"author": "Danny Coates <dannycoates@gmail.com>",
@@ -12,6 +12,8 @@
"engines" : { "node": ">=0.6.0" },
"dependencies": {},
"devDependencies": {
- "mocha": "*"
+ "mocha": "*",
+ "optimist": "*",
+ "async": "*"
}
}
View
23 test/endpoint_test.js
@@ -166,6 +166,29 @@ describe("Endpoint", function () {
s.listen(6969)
})
+ it("returns the whole body to the callback", function (done) {
+ var s = http.createServer(function (req, res) {
+ res.write("foo")
+ setTimeout(function () {
+ res.end("bar")
+ }, 10)
+ })
+ s.on('listening', function () {
+ var e = new Endpoint(http, '127.0.0.1', 6969, {timeout: 200, resolution: 10})
+ var body
+ e.request({path:'/foo', method: 'GET'}, function (err, response, b) {
+ body = b
+ })
+
+ setTimeout(function () {
+ s.close()
+ assert.equal(body, "foobar")
+ done()
+ }, 400)
+ })
+ s.listen(6969)
+ })
+
it("returns an error to the callback when pending > maxPending", function (done) {
var s = http.createServer(function (req, res) {
setTimeout(function () {
Please sign in to comment.
Something went wrong with that request. Please try again.