Fix #15, Support multipart post.

This commit is contained in:
Miao Jiang 2013-04-10 03:09:25 +08:00
parent e318a72006
commit 9c1cbb81c9
10 changed files with 239 additions and 30 deletions

View file

@ -1,10 +1,12 @@
// Generated by ToffeeScript 1.4.0
// Generated by ToffeeScript 1.6.2
(function() {
var Curl, curls, id, m, p;
var Curl, curls, e, id, m, p,
__hasProp = {}.hasOwnProperty;
try {
Curl = require(__dirname + '/../build/Release/node-curl').Curl;
} catch (e) {
} catch (_error) {
e = _error;
Curl = require(__dirname + '/../build/default/node-curl').Curl;
}
@ -12,11 +14,45 @@
return this.options[option_id] = value;
};
Curl.prototype.setopt_httppost = function(rows) {
var cols, k, option_id, row, v;
this.httppost = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = rows.length; _i < _len; _i++) {
row = rows[_i];
cols = [];
for (k in row) {
if (!__hasProp.call(row, k)) continue;
v = row[k];
k = k.toUpperCase();
if ((option_id = Curl.httppost_options[k]) != null) {
cols.push(option_id);
if (!(v instanceof Buffer)) {
v = new Buffer(v.toString());
}
cols.push(v);
} else {
throw new Error("invalid http post option " + k);
}
}
_results.push(cols);
}
return _results;
})();
this.setopt_httppost_(this.httppost);
return this;
};
Curl.prototype.setopt = function(option_name, value) {
var option, option_id;
option = option_name.toUpperCase();
if ((option_id = Curl.user_options[option]) != null) {
this.setopt_user_(option_id, value);
if (option === 'MULTIPART') {
this.setopt_httppost(value);
} else {
this.setopt_user_(option_id, value);
}
} else if ((option_id = Curl.slist_options[option]) != null) {
this.setopt_slist_(option_id, value);
} else if ((option_id = Curl.integer_options[option]) != null) {
@ -50,7 +86,8 @@
Curl.user_options = {
RAW: 'RAW',
DEBUG: 'DEBUG'
DEBUG: 'DEBUG',
MULTIPART: 'MULTIPART'
};
id = 0;