diff --git a/.gitignore b/.gitignore index 78e83bb..4375156 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ raw build +.lock-wscript diff --git a/.npmignore b/.npmignore index 78e83bb..4375156 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,3 @@ raw build +.lock-wscript diff --git a/examples/quick-start.js b/examples/quick-start.js index 61ff590..dbd8d33 100644 --- a/examples/quick-start.js +++ b/examples/quick-start.js @@ -14,7 +14,8 @@ curl(url, options, function(err, res) { res.close(); }); -curl('www.google.com', {VERBOSE: 1, RAW: 1}, function(err, res) { +curl('https://www.google.com', {VERBOSE: 1, RAW: 1}, function(err, res) { + console.info("\x1b[33meffetcive url: " + res.info('EFFECTIVE_URL') + "\x1b[0m"); console.info(res); res.close(); }); diff --git a/src/node-curl.h b/src/node-curl.h index e960bcf..ee3c20a 100644 --- a/src/node-curl.h +++ b/src/node-curl.h @@ -14,8 +14,6 @@ #define NODE_CURL_OPTION(name) NODE_CURL_OPTION_NX(name , CURLOPT_##name) #define NODE_CURL_EXPORT(name) export_curl_options(t, #name, name, sizeof(name) / sizeof(CurlOption)); - - class NodeCurl { struct CurlOption { @@ -37,6 +35,7 @@ class NodeCurl : in_curlm(false) { ++count; + // I know 2*4096 is magical world, but I have no idea the real memory curl will occupied v8::V8::AdjustAmountOfExternalAllocatedMemory(2*4096); object->SetPointerInInternalField(0, this); handle = v8::Persistent::New(object); @@ -329,6 +328,8 @@ class NodeCurl if (msg->msg == CURLMSG_DONE) { NodeCurl * curl = curls[msg->easy_handle]; + // ensure curl still exists, + // gc will delete the curl if there is no reference. if (msg->data.result == CURLE_OK) curl->on_end(msg); else @@ -385,20 +386,20 @@ class NodeCurl t->InstanceTemplate()->SetInternalFieldCount(1); // Set prototype methods - NODE_SET_PROTOTYPE_METHOD(t, "perform_", perform); - NODE_SET_PROTOTYPE_METHOD(t, "setopt_int_", setopt_int); - NODE_SET_PROTOTYPE_METHOD(t, "setopt_str_", setopt_str); - NODE_SET_PROTOTYPE_METHOD(t, "setopt_slist_", setopt_slist); + NODE_SET_PROTOTYPE_METHOD(t , "perform_" , perform); + NODE_SET_PROTOTYPE_METHOD(t , "setopt_int_" , setopt_int); + NODE_SET_PROTOTYPE_METHOD(t , "setopt_str_" , setopt_str); + NODE_SET_PROTOTYPE_METHOD(t , "setopt_slist_" , setopt_slist); - NODE_SET_PROTOTYPE_METHOD(t, "getinfo_int_", getinfo_int); - NODE_SET_PROTOTYPE_METHOD(t, "getinfo_str_", getinfo_str); - NODE_SET_PROTOTYPE_METHOD(t, "getinfo_double_", getinfo_double); - NODE_SET_PROTOTYPE_METHOD(t, "getinfo_slist_", getinfo_slist); + NODE_SET_PROTOTYPE_METHOD(t , "getinfo_int_" , getinfo_int); + NODE_SET_PROTOTYPE_METHOD(t , "getinfo_str_" , getinfo_str); + NODE_SET_PROTOTYPE_METHOD(t , "getinfo_double_" , getinfo_double); + NODE_SET_PROTOTYPE_METHOD(t , "getinfo_slist_" , getinfo_slist); NODE_SET_PROTOTYPE_METHOD(t, "close", close); - NODE_SET_METHOD(t, "process_", process); - NODE_SET_METHOD(t, "get_count", get_count); + NODE_SET_METHOD(t , "process_" , process); + NODE_SET_METHOD(t , "get_count" , get_count); // Set curl constants #include "string_options.h"