Comparing version 0.1.3 to 0.1.4
@@ -57,31 +57,36 @@ /* | ||
var post = function (method, req, res) { | ||
var code = ((req.method === method) ? 200 : 403), | ||
data = '', | ||
var data = '', | ||
gotData = false, | ||
sent = false, | ||
body = '', | ||
end = function () { | ||
if (!sent) { | ||
sent = true; | ||
var b = qs.parse(data); | ||
if (Object.keys(b).length > 0) { | ||
body = data; | ||
} else { | ||
body = String(Object.keys(b).length); | ||
} | ||
res.writeHead(code, headers); | ||
res.end(body); | ||
} | ||
}; | ||
sent = false; | ||
function end() { | ||
if (sent) { return; } | ||
if (req.body && Object.keys(req.body).length) { //Express | ||
var body = Object.keys(qs.parse(data)).length > 0 ? data : '', | ||
code; | ||
if (req.method === method) { | ||
code = body ? 200 : 204; | ||
} else { | ||
code = 403; | ||
} | ||
sent = true; | ||
res.writeHead(code, headers); | ||
res.end(body); | ||
} | ||
// Check if we have data, and aid Express' `req` object. | ||
if (req.body && Object.keys(req.body).length) { | ||
data = qs.stringify(req.body); | ||
gotData = true; | ||
data = qs.stringify(req.body); | ||
end(); | ||
} else { | ||
req.on('data', function (c) { | ||
data += c; | ||
gotData = true; | ||
data += c; | ||
}); | ||
@@ -91,4 +96,3 @@ | ||
//Seems as if the post doesn't have data | ||
//the end event doesn't fire?? | ||
// Seems as if the post doesn't have data the end event doesn't fire?? | ||
setTimeout(function () { | ||
@@ -95,0 +99,0 @@ if (!gotData) { |
@@ -5,3 +5,3 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"devDependencies": { | ||
@@ -8,0 +8,0 @@ "vows": "*", |
@@ -293,2 +293,15 @@ var vows = require('vows'), | ||
}, | ||
"and post with no body": { | ||
topic: function() { | ||
fetch({ | ||
method: 'POST', | ||
path: '/foo/bar/baz/echo/post', | ||
body: '' | ||
}, this.callback); | ||
}, | ||
"with query body": function(topic) { | ||
assert.equal(topic.code, 204); | ||
assert.equal(topic.body, ''); | ||
} | ||
}, | ||
"and post mismatch": { | ||
@@ -606,3 +619,3 @@ topic: function() { | ||
return [one, two] | ||
}, | ||
@@ -609,0 +622,0 @@ 'different paths': function(topic) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39658
933
35