英文:
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_HTTPHEADER
和 CURLOPT_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,
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论