sub run_fcgi_envvar_request()

in t/modules/proxy_fcgi.t [133:168]


sub run_fcgi_envvar_request
{
    my $fcgi_port = shift;
    my $uri       = shift;
    my $backend   = shift || "FCGI";

    # Launch the FCGI process.
    my $child = launch_envvar_echo_daemon($fcgi_port) if defined($fcgi_port);

    # Hit the backend.
    my $r = GET($uri);
    ok t_cmp($r->code, 200, "proxy to $backend backend works (" . $uri . ")");

    # Split the returned envvars into a dictionary.
    my %envs = ();

    foreach my $line (split /\n/, $r->content) {
        t_debug("> $line"); # log the response lines for debugging

        my @components = split /=/, $line, 2;
        $envs{$components[0]} = $components[1];
    }

    if(defined($fcgi_port)) {
        if ($r->code ge '500') {
            # Unknown failure, probably the request didn't hit the FCGI child
            # process, so it will hang waiting for our request
            kill 'TERM', $child;
        } else {
            # Rejoin the child FCGI process.
            waitpid($child, 0);
        }
    }

    return \%envs;
}