Skip to content

Commit

Permalink
[cleanup] plugin, server: Remove multipart from the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgerieQuentin committed Dec 14, 2012
1 parent b2d019f commit d195414
Showing 1 changed file with 0 additions and 127 deletions.
127 changes: 0 additions & 127 deletions lib/plugins/server/bslNet.nodejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var https = require('https');
var url = require('url');
var fs = require('fs');
var path = require('path');
var formidable = require('formidable');

var server_debug = false

Expand All @@ -20,10 +19,8 @@ var server_debug = false
/** @externType WebInfo.private.native_response */
/** @externType web_server_status */
/** @externType HttpRequest.msg_list */
/** @externType HttpRequest.multipart */
/** @externType list('a) */

/** @opaType HttpRequest.part */
/** @opaType WebClient.result('a) */
/** @opaType tuple_2('a, 'b) */
/** @opaType tuple_3('a, 'b, 'c) */
Expand Down Expand Up @@ -549,68 +546,6 @@ function get_remote_logs_params() {
return js_none;
}

/**
* @register {WebInfo.private.native_request, \
opa[continuation(option(HttpRequest.multipart))] -> void}
* @cpsBypass
*/
function get_multipart_cps(req, cont) {

// TODO
// - Build file progressively

var form = new formidable.IncomingForm();

// formidable doesn't give access to raw headers, so we have to collect them
// on our own. As the Opa stdlib expects every part to have a name, we index
// parts by their names. Hence, the multipart object is a map from field names
// (strings) to {headers, value} / {headers, file}.
var data = {};

form.onPart = function (part) {
part.on('end', function () {
if (!(part.name in data)) {
// Ignore for now duplicate names
data[part.name] = {headers: part.headers};
}
});
form.handlePart(part);
};

form.on('field', function (name, value) {
data[name].value = value;
});

form.on('file', function (name, file) {
data[name].file = file;
});

form.on('error', function (err) {
// TODO: terminate HTTP request too?
form.emit('return', js_none);
});

form.on('end', function () {
form.emit('return', js_some(data));
});

form.once('return', function (result) {
return_(cont, result);
});

form.parse(req.request);

return;
}

// Stub
/**
* @register {WebInfo.private.native_request -> opa[option(HttpRequest.multipart)]}
*/
function get_multipart(req) {
assert(false);
}

// Fold function f across obj's fields and values, using
// acc as the starting value. f must be in cps, with arguments
// (field_name, field_value, acc, continuation(acc)). k is the
Expand All @@ -634,68 +569,6 @@ function fold_cps(obj, f, acc, k) {
return iter(0)(acc);
}

/**
* @register {HttpRequest.multipart, 'acc, \
(HttpRequest.part, \
('a, (string, string, 'a, continuation('a) -> void), \
continuation('a) -> void), \
'acc, continuation('acc) -> void), \
continuation('acc) -> void}
* @cpsBypass
*/
function fold_multipart_cps(multipart, acc, folder, k) {

// Due to a bug in higher order projections, we have to bypass
// the cps transformation and manipulate continuations by hand.

function iter_multipart(name, part, acc, k) {
var res = empty_constructor();
add_field(res, 'name', name);

if ('file' in part) {
add_field(res, 'filename', part.file.filename);
add_field(res, 'content', function (cont) {
var res = empty_constructor();
add_field(res, 'content', binary_of_buffer(fs.readFileSync(part.file.path)));
return_(cont, res);
});
} else if ('value' in part) {
add_field(res, 'value', part.value);
}

function fold_header(acc, folder_h, k) {
// We need to convert header names to the format expected
// by Opa, i.e. "Header_Name"

var headers = {};

for (var name in part.headers) {
var newName =
name.replace("-", "_")
.replace(/(^|_)\w/g,
function (s) { return s.toUpperCase(); });
headers[newName] = part.headers[name];
}


return fold_cps(headers, folder_h, acc, k);
}

return folder(res, fold_header, acc, k);
}

return fold_cps(multipart, iter_multipart, acc, k);
}

/**
* @register {HttpRequest.multipart, 'acc, \
(HttpRequest.part, ('a, (string, string, 'a -> 'a) -> 'a), \
'acc -> 'acc) -> 'acc}
*/
function fold_multipart(multipart, acc, folder) {
assert(false);
}

/** @endModule */

/** @externType WebClient.failure */
Expand Down

0 comments on commit d195414

Please sign in to comment.