Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https seems not be supported #123

Open
yi-guo-546 opened this issue Aug 19, 2021 · 4 comments
Open

https seems not be supported #123

yi-guo-546 opened this issue Aug 19, 2021 · 4 comments

Comments

@yi-guo-546
Copy link

I want to use https to request, but I find it seems not be supported.
Is there any plans to support. Thank you.

@woodgear
Copy link
Contributor

you may take a look at #125 ,since that you could build a https request via

--- http2
--- curl_options: -k
--- curl_protocol: https
--- request
    GET /ping

@ezzye
Copy link

ezzye commented May 7, 2023

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. #Looks like your test exited with 2 before it could output anything.
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.

@zhuizhuhaomeng
Copy link
Contributor

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;
        }

@zhuizhuhaomeng
Copy link
Contributor

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants