“Unknown error” when using Net::Curl::Easy and “pushopt” options

huangapple go评论70阅读模式
英文:

curl "Unknown error" when using Net::Curl::Easy and "pushopt" options

问题

I need to pass authorization data to the proxy. However, this code (see below) results in an error.

#!/usr/bin/perl -w

$| = 1;

use Net::Curl::Easy qw(:constants);
 
my $easy = Net::Curl::Easy->new();
$easy->setopt( CURLOPT_URL, "https://checkip.amazonaws.com/" );
$easy->setopt( CURLOPT_VERBOSE, 1 );
$easy->setopt( CURLOPT_PROXY_SSL_VERIFYPEER , 0 );
$easy->setopt(CURLOPT_PROXY_SSL_VERIFYHOST, 0);
$easy->setopt(CURLOPT_SSL_VERIFYPEER, 0);
$easy->setopt(CURLOPT_USERAGENT, "curl");
$easy->setopt(CURLOPT_PROXY, "http://35.244.25.186:3128"); # some proxy
$easy->setopt(CURLOPT_HEADER, 1);
$easy->pushopt(CURLOPT_PROXYHEADER, ['username: apikey']); # when set "HTTPHEADER", everything is work fine

$easy->perform();

Tried to change proxyheader to httpheader, no errors. But, the header is sent to both the proxy and the target server, which does not suit me, since it is necessary that the header be sent only to the proxy.

Thank you in advance.

P.S. Python code that works similarly does not cause errors.

import sys
import pycurl

c = pycurl.Curl()
c.setopt(c.URL, 'https://checkip.amazonaws.com/')
c.setopt(c.VERBOSE, 1)
c.setopt(c.PROXY_SSL_VERIFYPEER , 0)
c.setopt(c.PROXY_SSL_VERIFYHOST, 0)
c.setopt(c.SSL_VERIFYPEER, 0)
c.setopt(c.USERAGENT, "curl")
c.setopt(c.PROXY, "http://35.244.25.186:3128")
c.setopt(c.PROXYHEADER, ['a: b'])
c.perform()
英文:

I need to pass authorization data to the proxy. However, this code (see below) results in an error.

#!/usr/bin/perl -w

$| = 1;

use Net::Curl::Easy qw(:constants);
 
my $easy = Net::Curl::Easy->new();
$easy->setopt( CURLOPT_URL, "https://checkip.amazonaws.com/" );
$easy->setopt( CURLOPT_VERBOSE, 1 );
$easy->setopt( CURLOPT_PROXY_SSL_VERIFYPEER , 0 );
$easy->setopt(CURLOPT_PROXY_SSL_VERIFYHOST, 0);
$easy->setopt(CURLOPT_SSL_VERIFYPEER, 0);
$easy->setopt(CURLOPT_USERAGENT, "curl");
$easy->setopt(CURLOPT_PROXY, "http://35.244.25.186:3128"); # some proxy
$easy->setopt(CURLOPT_HEADER, 1);
$easy->pushopt(CURLOPT_PROXYHEADER, ['username: apikey']); # when set "HTTPHEADER", everything is work fine

$easy->perform();

Tried to change proxyheader to httpheader, no errors. But, the header is sent to both the proxy and the target server, which does not suit me, since it is necessary that the header be sent only to the proxy.

Thank you in advance.

P.S. Python code that works similarly does not cause errors.

import sys
import pycurl

c = pycurl.Curl()
c.setopt(c.URL, 'https://checkip.amazonaws.com/')
c.setopt(c.VERBOSE, 1)
c.setopt(c.PROXY_SSL_VERIFYPEER , 0)
c.setopt(c.PROXY_SSL_VERIFYHOST, 0)
c.setopt(c.SSL_VERIFYPEER, 0)
c.setopt(c.USERAGENT, "curl")
c.setopt(c.PROXY, "http://35.244.25.186:3128")
c.setopt(c.PROXYHEADER, ['a: b'])
c.perform()

答案1

得分: 4

这似乎是Net::Curl中的一个错误。CURLOPT_HTTPHEADERCURLOPT_PROXYHEADER 应该都被视为一个列表。但是,CURLOPT_PROXYHEADER 没有被特别处理,所以很可能被视为一个整数参数,这导致了pushopt出现问题(因为没有列表),并且导致setopt出现分段错误(因为一个列表被视为整数)。

用于修复此问题的补丁可以在最近由OP打开的错误报告中找到:https://github.com/sparky/perl-Net-Curl/issues/73#issuecomment-1588512766:

--- a/Curl_Easy.xsh
+++ b/Curl_Easy.xsh
@@ -29,6 +29,7 @@ typedef enum {
 
 static const CURLoption perl_curl_easy_option_slist[] = {
        CURLOPT_HTTPHEADER,
+       CURLOPT_PROXYHEADER,
        CURLOPT_HTTP200ALIASES,
 #ifdef CURLOPT_MAIL_RCPT
        CURLOPT_MAIL_RCPT,
英文:

This looks like a bug to me in Net::Curl. CURLOPT_HTTPHEADER and CURLOPT_PROXYHEADER should be treated both as a list. But CURLOPT_PROXYHEADER wasn't specifically treated, so it likely was used as an integer argument only which broke pushopt (since no list) and caused a segmentation fault with setopt (since a list was treated as an integer).

Patch for fixing the issue can be found on the bug report recently opened (likely by the OP): https://github.com/sparky/perl-Net-Curl/issues/73#issuecomment-1588512766:

--- a/Curl_Easy.xsh
+++ b/Curl_Easy.xsh
@@ -29,6 +29,7 @@ typedef enum {
 
 static const CURLoption perl_curl_easy_option_slist[] = {
        CURLOPT_HTTPHEADER,
+       CURLOPT_PROXYHEADER,
        CURLOPT_HTTP200ALIASES,
 #ifdef CURLOPT_MAIL_RCPT
        CURLOPT_MAIL_RCPT,

huangapple
  • 本文由 发表于 2023年6月13日 05:05:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76460330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定