Skip to content

Commit 3fc5147

Browse files
authored
Fix the curl plugin hook curl_setopt by mistake. (#55)
1 parent 9fb087b commit 3fc5147

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/plugin/plugin_curl.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ use url::Url;
3232

3333
static CURLOPT_HTTPHEADER: c_long = 10023;
3434

35+
/// Prevent calling `curl_setopt` inside this plugin sets headers, the hook of
36+
/// `curl_setopt` is repeatedly called.
37+
static SKY_CURLOPT_HTTPHEADER: c_long = 9923;
38+
3539
thread_local! {
3640
static CURL_HEADERS: RefCell<HashMap<i64, ZVal>> = Default::default();
3741
}
@@ -70,9 +74,11 @@ impl CurlPlugin {
7074
validate_num_args(execute_data, 3)?;
7175

7276
let cid = Self::get_resource_id(execute_data)?;
77+
let options = execute_data.get_parameter(1).as_long();
7378

74-
if matches!(execute_data.get_parameter(1).as_long(), Some(n) if n == CURLOPT_HTTPHEADER)
75-
{
79+
if options == Some(SKY_CURLOPT_HTTPHEADER) {
80+
*execute_data.get_parameter(1) = CURLOPT_HTTPHEADER.into();
81+
} else if options == Some(CURLOPT_HTTPHEADER) {
7682
let value = execute_data.get_parameter(2);
7783
if value.get_type_info().is_array() {
7884
CURL_HEADERS
@@ -171,7 +177,7 @@ impl CurlPlugin {
171177
let ch = execute_data.get_parameter(0);
172178
call(
173179
"curl_setopt",
174-
&mut [ch.clone(), ZVal::from(CURLOPT_HTTPHEADER), val],
180+
&mut [ch.clone(), ZVal::from(SKY_CURLOPT_HTTPHEADER), val],
175181
)?;
176182
}
177183

0 commit comments

Comments
 (0)