diff --git a/lib/Curl.js b/lib/Curl.js index 1834e4d..6253d1e 100644 --- a/lib/Curl.js +++ b/lib/Curl.js @@ -12,9 +12,9 @@ return this.options[option_id] = value; }; - Curl.prototype.setopt = function(ooption, value) { + Curl.prototype.setopt = function(option_name, value) { var option, option_id; - option = ooption.toUpperCase(); + option = option_name.toUpperCase(); if ((option_id = Curl.user_options[option]) != null) { this.setopt_user_(option_id, value); } else if ((option_id = Curl.slist_options[option]) != null) { @@ -22,6 +22,9 @@ } else if ((option_id = Curl.integer_options[option]) != null) { this.setopt_int_(option_id, value >> 0); } else if ((option_id = Curl.string_options[option]) != null) { + if (value == null) { + throw new Error("Cannot set option " + option_name + " to " + value + "."); + } this.setopt_str_(option_id, value.toString()); } else { throw new Error("unsupported option " + option); diff --git a/lib/Curl.toffee b/lib/Curl.toffee index 0305a3a..69185e3 100644 --- a/lib/Curl.toffee +++ b/lib/Curl.toffee @@ -6,8 +6,8 @@ catch e Curl::setopt_user_ = (option_id, value) -> @options[option_id] = value -Curl::setopt = (ooption, value) -> - option = ooption.toUpperCase() +Curl::setopt = (option_name, value) -> + option = option_name.toUpperCase() # slist must be at the top of condition # the option exists in string_options too @@ -18,6 +18,8 @@ Curl::setopt = (ooption, value) -> else if (option_id = Curl.integer_options[option])? @setopt_int_ option_id, value >> 0 else if (option_id = Curl.string_options[option])? + if !value? + throw new Error("Cannot set option #{option_name} to #{value}.") @setopt_str_ option_id, value.toString() else throw new Error("unsupported option #{option}")