1#!/usr/bin/perl -w 2 3use strict; 4use lib 't/lib'; 5 6use Test::More tests => 2; 7use Test::HexString; 8 9use IO::Async::Loop; 10use IO::Async::Test; 11 12use Net::Async::FastCGI; 13 14use TestFCGI; 15 16my ( $S, $selfaddr ) = make_server_sock; 17 18my $loop = IO::Async::Loop->new(); 19testing_loop( $loop ); 20 21my $fcgi = Net::Async::FastCGI->new( 22 handle => $S, 23 on_request => sub { 24 my ( $fcgi, $req ) = @_; 25 26 my $data = $req->param( 'data' ); 27 28 $req->print_stdout( "You wrote $data" ); 29 $req->finish; 30 }, 31); 32 33$loop->add( $fcgi ); 34 35my $C = connect_client_sock( $selfaddr ); 36 37$C->syswrite( 38 # Begin 1 with FCGI_KEEP_CONN 39 fcgi_trans( type => 1, id => 1, data => "\0\1\1\0\0\0\0\0" ) . 40 # Begin 2 with FCGI_KEEP_CONN 41 fcgi_trans( type => 1, id => 2, data => "\0\1\1\0\0\0\0\0" ) . 42 # Parameters 1 43 fcgi_trans( type => 4, id => 1, data => "\4\5dataValue" ) . 44 # End of parameters 1 45 fcgi_trans( type => 4, id => 1, data => "" ) . 46 # Parameters 2 47 fcgi_trans( type => 4, id => 2, data => "\4\x0bdataOther value" ) . 48 # End of parameters 2 49 fcgi_trans( type => 4, id => 2, data => "" ) . 50 # No STDIN 1 51 fcgi_trans( type => 5, id => 1, data => "" ) 52); 53 54my $expect; 55 56$expect = 57 # STDOUT 58 fcgi_trans( type => 6, id => 1, data => "You wrote Value" ) . 59 # End of STDOUT 60 fcgi_trans( type => 6, id => 1, data => "" ) . 61 # End request 62 fcgi_trans( type => 3, id => 1, data => "\0\0\0\0\0\0\0\0" ); 63 64my $buffer; 65 66$buffer = ""; 67 68wait_for_stream { length $buffer >= length $expect } $C => $buffer; 69 70is_hexstr( $buffer, $expect, 'FastCGI end request record' ); 71 72$C->syswrite( 73 # No STDIN 2 74 fcgi_trans( type => 5, id => 2, data => "" ) 75); 76 77$expect = 78 # STDOUT 79 fcgi_trans( type => 6, id => 2, data => "You wrote Other value" ) . 80 # End of STDOUT 81 fcgi_trans( type => 6, id => 2, data => "" ) . 82 # End request 83 fcgi_trans( type => 3, id => 2, data => "\0\0\0\0\0\0\0\0" ); 84 85$buffer = ""; 86 87wait_for_stream { length $buffer >= length $expect } $C => $buffer; 88 89is_hexstr( $buffer, $expect, 'FastCGI end request record' ); 90