Fix the curl plugin hook curl_setopt by mistake. (#55)
diff --git a/src/plugin/plugin_curl.rs b/src/plugin/plugin_curl.rs
index 8cc1f17..61ae88c 100644
--- a/src/plugin/plugin_curl.rs
+++ b/src/plugin/plugin_curl.rs
@@ -32,6 +32,10 @@
static CURLOPT_HTTPHEADER: c_long = 10023;
+/// Prevent calling `curl_setopt` inside this plugin sets headers, the hook of
+/// `curl_setopt` is repeatedly called.
+static SKY_CURLOPT_HTTPHEADER: c_long = 9923;
+
thread_local! {
static CURL_HEADERS: RefCell<HashMap<i64, ZVal>> = Default::default();
}
@@ -70,9 +74,11 @@
validate_num_args(execute_data, 3)?;
let cid = Self::get_resource_id(execute_data)?;
+ let options = execute_data.get_parameter(1).as_long();
- if matches!(execute_data.get_parameter(1).as_long(), Some(n) if n == CURLOPT_HTTPHEADER)
- {
+ if options == Some(SKY_CURLOPT_HTTPHEADER) {
+ *execute_data.get_parameter(1) = CURLOPT_HTTPHEADER.into();
+ } else if options == Some(CURLOPT_HTTPHEADER) {
let value = execute_data.get_parameter(2);
if value.get_type_info().is_array() {
CURL_HEADERS
@@ -171,7 +177,7 @@
let ch = execute_data.get_parameter(0);
call(
"curl_setopt",
- &mut [ch.clone(), ZVal::from(CURLOPT_HTTPHEADER), val],
+ &mut [ch.clone(), ZVal::from(SKY_CURLOPT_HTTPHEADER), val],
)?;
}