Browse Source

Handle bad requests in simplified parser API

v0.7.4-release
Felix Geisendörfer 15 years ago
parent
commit
f86c1783b7
  1. 10
      lib/multipart.js
  2. 9
      test/mjsunit/test-multipart.js

10
lib/multipart.js

@ -1,9 +1,17 @@
var sys = require("sys");
exports.parse = function(options) {
var stream = new exports.Stream(options);
var promise = new process.Promise();
try {
var stream = new exports.Stream(options);
} catch (e) {
setTimeout(function() {
promise.emitError(e);
}, 0);
return promise;
}
var parts = {};
stream.addListener('part', function(part) {
var name = part.name;

9
test/mjsunit/test-multipart.js

@ -12,7 +12,7 @@ var badRequests = 0;
var parts = {};
var respond = function(res, text) {
requests++;
if (requests == 3) {
if (requests == 4) {
server.close();
}
@ -29,6 +29,7 @@ var server = http.createServer(function(req, res) {
})
.addErrback(function() {
badRequests++;
respond(res, 'no thanks');
});
return;
}
@ -88,9 +89,13 @@ var badRequest = client.request('POST', '/', {'Content-Type': 'something', 'Cont
badRequest.sendBody(fixture.reply, 'binary');
badRequest.finish();
var simpleBadRequest = client.request('POST', '/', {'X-Use-Simple-Api': 'yes', 'Content-Type': 'something', 'Content-Length': fixture.reply.length});
simpleBadRequest.sendBody(fixture.reply, 'binary');
simpleBadRequest.finish();
process.addListener('exit', function() {
puts("done");
assert.equal(2, parts_complete);
assert.equal(2, parts_reveived);
assert.equal(1, badRequests);
assert.equal(2, badRequests);
});
Loading…
Cancel
Save