fixes #2 CookieList returning same data for each cookie

new structure for node-curl
This commit is contained in:
jiangfriend@gmail.com 2012-05-28 19:55:17 +08:00
parent e791a14c6e
commit 90f3135c8c
11 changed files with 461 additions and 237 deletions

View file

@ -1,8 +1,6 @@
// Generated by ToffeeScript 1.2.0-0
// Generated by ToffeeScript 1.3.3
(function() {
var Curl, curl, curl_id, curls,
__slice = [].slice,
__hasProp = {}.hasOwnProperty;
var Curl, CurlBuilder, curl;
try {
Curl = require(__dirname + '/../build/Release/node-curl').Curl;
@ -10,6 +8,8 @@
Curl = require(__dirname + '/../build/default/node-curl').Curl;
}
CurlBuilder = require(__dirname + '/CurlBuilder');
Curl.prototype.setopt_user_ = function(option_id, value) {
return this.options[option_id] = value;
};
@ -46,18 +46,20 @@
}
};
Curl.user_options = {
RAW: 'RAW'
};
Curl.prototype.perform = function() {
this.perform_();
return Curl.process();
};
Curl.user_options = {
RAW: 'RAW'
};
Curl.process = function() {
var once;
if (Curl.in_process) return;
if (Curl.in_process) {
return;
}
return (once = function() {
var num;
num = Curl.process_();
@ -70,85 +72,7 @@
})();
};
curl_id = 0;
curls = {};
curl = function() {
var args, c, cb, k, length, options, url, v;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
cb = args.pop();
url = args[0], options = args[1];
if (options == null) options = {};
c = new Curl();
c.options = {};
c.id = ++curl_id;
curls[c.id] = c;
c.setopt('FOLLOWLOCATION', 1);
c.setopt('ACCEPT_ENCODING', 'gzip');
c.chunks = [];
length = 0;
for (k in options) {
if (!__hasProp.call(options, k)) continue;
v = options[k];
c.setopt(k, v);
}
c.on_write = function(chunk) {
c.chunks.push(chunk);
return length += chunk.length;
};
c.on_end = function() {
var chunk, data, position, res, _i, _len, _ref,
_this = this;
data = new Buffer(length);
position = 0;
_ref = c.chunks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
chunk = _ref[_i];
chunk.copy(data, position);
position += chunk.length;
}
c.chunks = [];
res = {};
res.curl_ = c;
delete curls[c.id];
if (c.options.RAW) {
res.body = data;
} else {
res.body = data.toString();
}
res.status = res.code = c.getinfo('RESPONSE_CODE');
res.info = function(info) {
if (this.curl_ == null) throw new Error('curl is closed');
return this.curl_.getinfo(info);
};
res.close = function() {
if (this.curl_ != null) this.curl_.close();
this.curl_ = null;
return this.body = null;
};
return process.nextTick(function() {
return cb(null, res);
});
};
c.on_error = function(err) {
var _this = this;
curls[c.id].close();
delete curls[c.id];
return process.nextTick(function() {
return cb(err, null);
});
};
c.setopt('URL', url);
c.perform();
return c;
};
curl.Curl = Curl;
curl.get_count = function() {
return Curl.get_count();
};
curl = CurlBuilder.create();
module.exports = curl;