Open yi-guo-546 opened 3 years ago
you may take a look at https://github.com/openresty/test-nginx/pull/125 ,since that you could build a https request via
--- http2
--- curl_options: -k
--- curl_protocol: https
--- request
GET /ping
I have tried this with a macbook but does not work due to:`Could not open /proc/net/tcp. No such file or directory at /Users/xxxxxx/perl5/lib/perl5/Test/Nginx/Util.pm line 265.
` I think this only works with linux due to use of /proc/net/tcp.
I replaced
sub is_tcp_port_used($) {
my $port = shift;
my $filename = "/proc/net/tcp";
open my $fh, $filename or die "Could not open $filename. $!";
while (<$fh>) {
my $line = $_;
if ($line =~ /^ *\d+: [0-9A-F]+:([0-9A-F]+) /) {
if ($port == hex($1)) {
close $fh;
return 1;
}
}
}
close $fh;
return 0;
}
with
sub is_tcp_port_used($) {
my $port = shift;
my $cmd = "lsof -i tcp:$port";
my $output = `$cmd`;
if ($output) {
return 1;
} else {
return 0;
}
}
in Util.pm
and it works.
Tell me how you distinguish between macos, linux etc and I will submit a PR. Updated code per zhuizhuhaomeng comment.
Here is an example. you can change VMS to linux and so on.
if ($^O eq 'VMS') {
require ExtUtils::CBuilder;
my $builder = ExtUtils::CBuilder->new(
quiet => 1,
);
return $builder->have_compiler;
}
by the way, "lsof -i tcp:$port -sTCP:LISTEN" is not correct. We want to test if the port is in used. So you should use "lsof -i tcp:$port"
I want to use https to request, but I find it seems not be supported. Is there any plans to support. Thank you.