diff --git a/src/node-curl.h b/src/node-curl.h index f194252..39c18f8 100644 --- a/src/node-curl.h +++ b/src/node-curl.h @@ -7,6 +7,7 @@ #include #include #include +#include #define NODE_CURL_EXPORT(name) export_curl_options(t, #name, name, sizeof(name) / sizeof(CurlOption)); @@ -28,6 +29,7 @@ class NodeCurl v8::Persistent handle; bool in_curlm; std::vector slists; + std::map strings; NodeCurl(v8::Handle object) : in_curlm(false) @@ -215,7 +217,14 @@ class NodeCurl static v8::Handle setopt_str(const v8::Arguments & args) { - return unwrap(args.This())->setopt(args[0], *v8::String::Utf8Value(args[1]) ); + // Create a string copy + // https://github.com/jiangmiao/node-curl/issues/3 + NodeCurl * node_curl = unwrap(args.This()); + int key = args[0]->Int32Value(); + v8::String::Utf8Value value(args[1]); + int length = value.length(); + node_curl->strings[key] = std::string(*value, length); + return unwrap(args.This())->setopt(args[0], node_curl->strings[key].c_str() ); } static v8::Handle setopt_slist(const v8::Arguments & args)