2009-10-05 15:46:31 +02:00
|
|
|
node.mixin(require("common.js"));
|
2009-09-28 12:36:36 +02:00
|
|
|
http = require("/http.js");
|
2009-09-27 16:52:33 +02:00
|
|
|
|
|
|
|
var multipart = require('/multipart.js');
|
2009-10-06 21:38:35 +02:00
|
|
|
var fixture = require('fixtures/multipart.js');
|
|
|
|
|
2009-09-27 16:52:33 +02:00
|
|
|
var port = 8222;
|
|
|
|
var parts_reveived = 0;
|
|
|
|
var parts_complete = 0;
|
|
|
|
var parts = {};
|
|
|
|
|
2009-09-28 12:36:36 +02:00
|
|
|
var server = http.createServer(function(req, res) {
|
2009-09-27 16:52:33 +02:00
|
|
|
var stream = new multipart.Stream(req);
|
|
|
|
|
|
|
|
stream.addListener('part', function(part) {
|
|
|
|
parts_reveived++;
|
|
|
|
|
2009-10-06 21:38:35 +02:00
|
|
|
var name = part.headers['content-disposition'].name;
|
2009-09-27 16:52:33 +02:00
|
|
|
|
|
|
|
if (parts_reveived == 1) {
|
2009-10-06 21:38:35 +02:00
|
|
|
assertEquals('reply', name);
|
2009-09-27 16:52:33 +02:00
|
|
|
} else if (parts_reveived == 2) {
|
2009-10-06 21:38:35 +02:00
|
|
|
assertEquals('fileupload', name);
|
2009-09-27 16:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parts[name] = '';
|
|
|
|
part.addListener('body', function(chunk) {
|
|
|
|
parts[name] += chunk;
|
|
|
|
});
|
|
|
|
part.addListener('complete', function(chunk) {
|
|
|
|
if (parts_reveived == 1) {
|
2009-10-06 21:38:35 +02:00
|
|
|
assertEquals('yes', parts[name]);
|
2009-09-27 16:52:33 +02:00
|
|
|
} else if (parts_reveived == 2) {
|
2009-10-06 21:38:35 +02:00
|
|
|
assertEquals('/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg', parts[name]);
|
2009-09-27 16:52:33 +02:00
|
|
|
}
|
|
|
|
parts_complete++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
stream.addListener('complete', function() {
|
|
|
|
res.sendHeader(200, {"Content-Type": "text/plain"});
|
|
|
|
res.sendBody('thanks');
|
|
|
|
res.finish();
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(port);
|
|
|
|
|
2009-10-06 21:38:35 +02:00
|
|
|
var client = http.createClient(port);
|
|
|
|
var request = client.post('/', {'Content-Type': 'multipart/form-data; boundary=AaB03x', 'Content-Length': fixture.reply.length});
|
|
|
|
request.sendBody(fixture.reply, 'binary');
|
|
|
|
request.finish();
|
2009-09-27 16:52:33 +02:00
|
|
|
|
|
|
|
process.addListener('exit', function() {
|
2009-10-06 21:38:35 +02:00
|
|
|
puts("done");
|
2009-09-27 16:52:33 +02:00
|
|
|
assertEquals(2, parts_complete);
|
2009-10-06 21:38:35 +02:00
|
|
|
assertEquals(2, parts_reveived);
|
2009-09-28 12:06:30 +02:00
|
|
|
});
|