You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2023/03/08 01:57:25 UTC

[skywalking-php] branch master updated: Fix the curl plugin hook curl_setopt by mistake. (#55)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-php.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fc5147  Fix the curl plugin hook curl_setopt by mistake. (#55)
3fc5147 is described below

commit 3fc51477a133ef1c70a865ddaa07fe381a989aaa
Author: jmjoy <jm...@apache.org>
AuthorDate: Wed Mar 8 09:57:19 2023 +0800

    Fix the curl plugin hook curl_setopt by mistake. (#55)
---
 src/plugin/plugin_curl.rs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

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 @@ use url::Url;
 
 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 @@ impl CurlPlugin {
                 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 @@ impl CurlPlugin {
                     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],
                     )?;
                 }