File: request_mode_heuristics.t

package info (click to toggle)
libweb-simple-perl 0.033-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: perl: 1,622; makefile: 7
file content (52 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use strictures;

use Test::More 0.88;
use Web::Simple::Application;
use Socket;

run();
done_testing;

sub run {

    my $a = Web::Simple::Application->new;

    my ( $cli, $cgi, $fcgi, $test ) = qw( cli cgi fcgi test );

    my $res;
    no warnings 'redefine';
    local *Web::Simple::Application::_run_fcgi             = sub { $res = "fcgi" };
    local *Web::Simple::Application::_run_cgi              = sub { $res = "cgi" };
    local *Web::Simple::Application::_run_cli              = sub { $res = "cli" };
    local *Web::Simple::Application::_run_cli_test_request = sub { $res = "test" };
    use strictures;

    {
        $a->run;
        is $res, "cli", "empty invocation goes to CLI mode";
    }

  SKIP: {
        skip "windows does not support the needed socket manipulation", 2 if $^O eq 'MSWin32' or $^O eq 'cygwin';
        {
            socket my $socket, AF_INET, SOCK_STREAM, 0 or die "socket: $!";
            open my $old_in, '<&STDIN' or die "open: $!";
            open STDIN, '<&', $socket or die "open: $!";
            $a->run;
            is $res, "fcgi", "STDIN being a socket means FCGI";
            open STDIN, '<&', $old_in or die "open: $!";
        }

        {
            local $ENV{GATEWAY_INTERFACE} = "CGI 1.1";
            socket my $socket, AF_INET, SOCK_STREAM, 0 or die "socket: $!";
            open my $old_in, '<&STDIN' or die "open: $!";
            open STDIN, '<&', $socket or die "open: $!";
            $a->run;
            isnt $res, "fcgi", "STDIN being a socket doesn't mean FCGI if GATEWAY_INTERFACE is set";
            open STDIN, '<&', $old_in or die "open: $!";
        }
    }

    return;
}