Build.PL100664001751001751 45513323125150 16153 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use Module::Build::Tiny 0.035; Build_PL(); Changes100664001751001751 203513323125150 16166 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09Revision history for Perl extension FCGI::Client 0.09 2018-07-16T14:23:14Z - Switch to Minilla https://github.com/tokuhirom/p5-fcgi-client/pull/2 - Switch to Moo https://github.com/tokuhirom/p5-fcgi-client/pull/3 0.08 - fixed default timeout was 10secs. previsously it was documented as 10secs, but it is implemented as 1sec. https://rt.cpan.org/Ticket/Display.html?id=71100 0.07 - make FCGI::Client::Connection->timeout as writable(Jonas) 0.06 - fixed large packet issue (trunaev++) 0.05 - remove unused dependency to autodie, Try::Tiny. - fixed bad error handler in FCGI/Client/Connection.pm. https://rt.cpan.org/Ticket/Display.html?id=57374 (reported by mmcleric) 0.04 - fixed bug: support long input 0.03 - fixed bug: long key/value pairs in headers now conform to spec (peterkeen) 0.02 - better error handler - fixed alarm handler, and localize it 0.01_02 - fixed alarm bug - fixed deps 0.01_01 - shipped first dev release LICENSE100664001751001751 4413113323125150 15723 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09This software is copyright (c) 2011 by Tokuhiro Matsuno Etokuhirom @*(#RJKLFHFSDLJF gmail.comE. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2011 by Tokuhiro Matsuno Etokuhirom @*(#RJKLFHFSDLJF gmail.comE. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2011 by Tokuhiro Matsuno Etokuhirom @*(#RJKLFHFSDLJF gmail.comE. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End META.json100664001751001751 511013323125150 16311 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09{ "abstract" : "client library for fastcgi protocol", "author" : [ "Tokuhiro Matsuno " ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.0.9", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "FCGI-Client", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "Module::Build::Tiny" : "0.035" } }, "develop" : { "requires" : { "FCGI" : "0", "HTTP::Request" : "0", "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.04", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7", "Test::TCP" : "0" } }, "runtime" : { "requires" : { "IO::Socket::UNIX" : "0", "Moo" : "2", "Type::Tiny" : "0", "perl" : "5.008001" } } }, "provides" : { "FCGI::Client" : { "file" : "lib/FCGI/Client.pm", "version" : "0.09" }, "FCGI::Client::Connection" : { "file" : "lib/FCGI/Client/Connection.pm" }, "FCGI::Client::Constant" : { "file" : "lib/FCGI/Client/Constant.pm" }, "FCGI::Client::Record" : { "file" : "lib/FCGI/Client/Record.pm" }, "FCGI::Client::RecordFactory" : { "file" : "lib/FCGI/Client/RecordFactory.pm" }, "FCGI::Client::RecordHeader" : { "file" : "lib/FCGI/Client/RecordHeader.pm" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/tokuhirom/p5-fcgi-client/issues" }, "homepage" : "https://github.com/tokuhirom/p5-fcgi-client", "repository" : { "url" : "git://github.com/tokuhirom/p5-fcgi-client.git", "web" : "https://github.com/tokuhirom/p5-fcgi-client" } }, "version" : "0.09", "x_authority" : "cpan:TOKUHIROM", "x_contributors" : [ "Peter Keen ", "Tokuhiro Matsuno " ], "x_serialization_backend" : "JSON::PP version 2.27400" } README.md100664001751001751 155313323125150 16156 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09# NAME FCGI::Client - client library for fastcgi protocol # SYNOPSIS use FCGI::Client; my $sock = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => $port, ) or die $!; my $client = FCGI::Client::Connection->new( sock => $sock ); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', }, '' ); # DESCRIPTION FCGI::Client is client library for fastcgi protocol. # AUTHOR Tokuhiro Matsuno <tokuhirom @\*(#RJKLFHFSDLJF gmail.com> # THANKS TO peterkeen # SEE ALSO [FCGI](https://metacpan.org/pod/FCGI), [http://www.fastcgi.com/drupal/node/6?q=node/22](http://www.fastcgi.com/drupal/node/6?q=node/22) # LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. cpanfile100664001751001751 44013323125150 16355 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09requires 'Moo', '2'; requires 'IO::Socket::UNIX'; requires 'perl', '5.008001'; requires 'Type::Tiny'; on build => sub { requires 'Test::More'; }; on develop => sub { requires 'Test::TCP'; requires 'HTTP::Request'; requires 'FCGI'; requires 'Test::Perl::Critic'; }; Client.pm100664001751001751 202313323125150 17722 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/lib/FCGIpackage FCGI::Client; use warnings; use strict; use 5.008001; our $VERSION = '0.09'; use Carp; use FCGI::Client::Connection; use FCGI::Client::Record; use FCGI::Client::RecordFactory; 1; __END__ =head1 NAME FCGI::Client - client library for fastcgi protocol =head1 SYNOPSIS use FCGI::Client; my $sock = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => $port, ) or die $!; my $client = FCGI::Client::Connection->new( sock => $sock ); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', }, '' ); =head1 DESCRIPTION FCGI::Client is client library for fastcgi protocol. =head1 AUTHOR Tokuhiro Matsuno Etokuhirom @*(#RJKLFHFSDLJF gmail.comE =head1 THANKS TO peterkeen =head1 SEE ALSO L, L =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Connection.pm100664001751001751 1077713323125150 22060 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/lib/FCGI/Clientpackage FCGI::Client::Connection; use strict; use warnings; use FCGI::Client::Constant; use Time::HiRes qw(time); use List::Util qw(max); use POSIX qw(EAGAIN); use FCGI::Client::Record; use FCGI::Client::RecordFactory; use Types::Standard qw/Int/; use Moo; has sock => ( is => 'ro', required => 1, ); has timeout => ( is => 'rw', isa => Int, default => 10, ); no Moo; sub request { my ($self, $env, $content) = @_; local $SIG{PIPE} = "IGNORE"; { local $SIG{ALRM} = sub { Carp::confess('REQUEST_TIME_OUT') }; my $orig_alarm = alarm($self->timeout) || 0; $self->_send_request($env, $content); my @res = $self->_receive_response($self->sock); alarm($orig_alarm); return @res; } } sub _receive_response { my ($self, $sock) = @_; my ($stdout, $stderr); while (my $res = $self->_read_record($self)) { my $type = $res->type; if ($type == FCGI_STDOUT) { $stdout .= $res->content; } elsif ($type == FCGI_STDERR) { $stderr .= $res->content; } elsif ($type == FCGI_END_REQUEST) { my $appstatus = unpack('N', $res->content); $sock->close(); return ($stdout, $stderr, $appstatus); } else { die "unknown response type: " . $res->type; } } die 'connection breaked from server process?'; } sub _send_request { my ($self, $env, $content) = @_; my $reqid = 1; $self->sock->print(FCGI::Client::RecordFactory->create_request($reqid, $env, $content)); } sub _read_record { my ($self) = @_; my $header_raw = ''; while (length($header_raw) != FCGI_HEADER_LEN) { $self->_read_timeout(\$header_raw, FCGI_HEADER_LEN-length($header_raw), length($header_raw)) or return; } my $header = FCGI::Client::RecordHeader->new(raw => $header_raw); my $content_length = $header->content_length; my $content = ''; if ($content_length != 0) { while (length($content) != $content_length) { $self->_read_timeout(\$content, $content_length-length($content), length($content)) or return; } } my $padding_length = $header->padding_length; my $padding = ''; if ($padding_length != 0) { while (length($padding) != $padding_length) { $self->_read_timeout(\$padding, $padding_length, 0) or return; } } return FCGI::Client::Record->new( header => $header, content => $content, ); } # returns 1 if socket is ready, undef on timeout sub _wait_socket { my ( $self, $sock, $is_write, $wait_until ) = @_; do { my $vec = ''; vec( $vec, $sock->fileno, 1 ) = 1; if ( select( $is_write ? undef : $vec, $is_write ? $vec : undef, undef, max( $wait_until - time, 0 ) ) > 0 ) { return 1; } } while ( time < $wait_until ); return; } # returns (positive) number of bytes read, or undef if the socket is to be closed sub _read_timeout { my ( $self, $buf, $len, $off, ) = @_; my $sock = $self->sock; my $timeout = $self->timeout; my $wait_until = time + $timeout; while ( $self->_wait_socket( $sock, undef, $wait_until ) ) { if ( my $ret = $sock->sysread( $$buf, $len, $off ) ) { return $ret; } elsif ( !( !defined($ret) && $! == EAGAIN ) ) { last; } } return; } 1; __END__ =head1 NAME FCGI::Client::Connection - connection to FastCGI server =head1 DESCRIPTION This module handles connection to FastCGI server. =head1 ATTRIBUTES =over 4 =item sock the socket object. =item timeout read only integer value, default is 10seconds. =back =head1 METHODS =over 4 =item my ($stdout, $stderr, $appstatus) = $self->request($env, $content) $env is environment hash, same as CGI.$content is request body string. This method returns $stdout and $stderr strings.When error got, return undef. $appstatus is the status code of FastCGI server, this is one of the following code. #define FCGI_REQUEST_COMPLETE 0 #define FCGI_CANT_MPX_CONN 1 #define FCGI_OVERLOADED 2 #define FCGI_UNKNOWN_ROLE 3 These constants defined at L. =back =head1 FAQ =over 4 =item Why don't support FCGI_KEEP_CONN? FCGI_KEEP_CONN is not used by lighttpd's mod_fastcgi.c, and mod_fast_cgi for apache. And, FCGI.xs doesn't support it. I seems FCGI_KEEP_CONN is not used in real world. =back Constant.pm100664001751001751 311113323125150 21512 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/lib/FCGI/Clientuse strict; use warnings; package FCGI::Client::Constant; sub import { my $const = { # Number of bytes in a FCGI_Header. Future versions of the protocol # will not reduce this number. FCGI_HEADER_LEN => 8, # protocol version FCGI_VERSION_1 => 1, # Mask for flags component of FCGI_BeginRequestBody FCGI_KEEP_CONN => 1, # request role FCGI_RESPONDER => 1, FCGI_AUTHORIZER => 2, FCGI_FILTER => 3, # Values for protocolStatus component of FCGI_EndRequestBody FCGI_REQUEST_COMPLETE => 0, FCGI_CANT_MPX_CONN => 1, FCGI_OVERLOADED => 2, FCGI_UNKNOWN_ROLE => 3, # packet type FCGI_BEGIN_REQUEST => 1, FCGI_ABORT_REQUEST => 2, FCGI_END_REQUEST => 3, FCGI_PARAMS => 4, FCGI_STDIN => 5, FCGI_STDOUT => 6, FCGI_STDERR => 7, FCGI_DATA => 8, FCGI_GET_VALUES => 9, FCGI_GET_VALUES_RESULT => 10, FCGI_UNKNOWN_TYPE => 11, }; my $pkg = caller(0); no strict 'refs'; while (my ($k, $v) = each %$const) { *{"$pkg\::$k"} = sub () { $v }; } } 1; __END__ =head1 NAME FCGI::Client::Constant - constants for FCGI =head1 DESCRIPTION This module defines constants for FCGI protocol. If you want to know what's included in this module, see the source code. =head1 SEE ALSO L =cut Record.pm100664001751001751 210013323125150 21134 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/lib/FCGI/Clientpackage FCGI::Client::Record; use strict; use warnings; use FCGI::Client::Constant; use FCGI::Client::RecordHeader; use Types::Standard qw/Str/; use Moo; has header => ( is => 'ro', isa => sub { die "header must be FCGI::Client::RecordHeader" unless UNIVERSAL::isa($_[0], 'FCGI::Client::RecordHeader') }, handles => [qw/request_id content_length type/] ); has content => ( is => 'ro', isa => Str ); no Moo; __PACKAGE__->meta->make_immutable; __END__ =head1 NAME FCGI::Client::Record - record object for FCGI =head1 SYNOPSIS my $record = FCGI::Client::Record->new(header => $header, content => $content); say $record->type; =head1 DESCRIPTION This module is record class for L. =head1 ATTRIBUTES =over 4 =item header 'header' attribute is instance of L. =item content 'content' attribute is string of record content. =back =head1 METHOD =over 4 =item $self->request_id() =item $self->content_length() =item $self->type() shortcut of $self->header->I() =back =head1 SEE ALSO L RecordFactory.pm100664001751001751 775013323125150 22504 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/lib/FCGI/Clientpackage FCGI::Client::RecordFactory; use strict; use warnings; use FCGI::Client::Constant; sub create_request { my ($self, $reqid, $env, $content) = @_; my $factory = __PACKAGE__; my $flags = 0; return join('', $factory->build_begin_request($reqid, FCGI_RESPONDER, $flags), $factory->build_params($reqid, %$env), $factory->build_params($reqid), ($content ? $factory->build_stdin($reqid, $content) : ''), $factory->build_stdin($reqid, ''), ); } # generate generic record sub build_base { my ($class, $type, $request_id, $content) = @_; # 0 unsigned char version; # 1 unsigned char type; # 2 unsigned char requestIdB1; <= (B1<<8)+B0, network byte order # 3 unsigned char requestIdB0; # 4 unsigned char contentLengthB1; # 5 unsigned char contentLengthB0; # 6 unsigned char paddingLength; # 7 unsigned char reserved; # unsigned char contentData[contentLength]; # unsigned char paddingData[paddingLength]; # # n => An unsigned short (16−bit) in "network" (big−endian) order. # C => An unsigned char (octet) value. my $build_record = sub { my $in = $_[0]; pack('CCnnCC', FCGI_VERSION_1, $type, $request_id, length($in), 0, 0, ) . $in }; if (length($content) > 0) { my $buf = ''; while( length( $content ) > 65535 ) { $buf .= $build_record->( substr( $content, 0, 65535 ) ); $content = substr( $content, 65535 ); } $buf .= $build_record->($content); return $buf; } else { return $build_record->(''); } } # generate FCGI_BEGIN_REQUEST record sub build_begin_request { my ($class, $request_id, $role, $flags) = @_; # typedef struct { # unsigned char roleB1; # unsigned char roleB0; # unsigned char flags; # unsigned char reserved[5]; # } FCGI_BeginRequestBody; my $content = pack( 'nCCCCCC', $role, $flags, 0,0,0,0,0 ); $class->build_base(FCGI_BEGIN_REQUEST, $request_id, $content); } # generate FCGI_PARAMS record # 0x80000000 means: The high-order bit of the first byte of a length indicates the length's encoding. A high-order zero implies a one-byte encoding, a one a four-byte encoding. sub build_params { my ($class, $request_id, %params) = @_; my $content = ''; while (my ($k, $v) = each %params) { my $klen = length($k); my $vlen = length($v); if ($klen < 127) { $content .= pack('C', $klen); # C: An unsigned char (octet) value. } else { $klen = $klen | 0x80000000; $content .= pack('N', $klen); # N: An unsigned quad value. } if ($vlen < 127) { $content .= pack('C', $vlen); } else { $vlen = $vlen | 0x80000000; $content .= pack('N', $vlen); } $content .= $k; $content .= $v; } $class->build_base(FCGI_PARAMS, $request_id, $content); } # generate FCGI_STDIN record sub build_stdin { my ($class, $request_id, $content) = @_; $content ||= ''; $class->build_base(FCGI_STDIN, $request_id, $content); } 1; __END__ =head1 NAME FCGI::Client::RecordFactory - FCGI record factory =head1 HIGH LEVEL API METHODS =over 4 =item FCGI::Client::RecordFactory->create_request($reqid, $env, $content); This method creates set of request records.$env is environment variables same as CGI. $content is request body.This method returns string of request records.You can send it to socket. =back =head1 LOW LEVEL API METHODS =over 4 =item FCGI::Client::RecordFactory->build_begin_request($reqid, FCGI_RESPONDER, $flags); build FCGI_BEGIN_REQUEST record. =item FCGI::Client::RecordFactory->build_params($reqid, %$env) build FCGI_PARAMS record. =item FCGI::Client::RecordFactory->build_stdin($reqid, $content); build FCGI_STDIN record. =back =head1 SEE ALSO L RecordHeader.pm100664001751001751 207313323125150 22256 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/lib/FCGI/Clientpackage FCGI::Client::RecordHeader; use strict; use warnings; use FCGI::Client::Constant; use Types::Standard qw/Str/; use Moo; has raw => ( is => 'ro', isa => Str ); no Moo; sub content_length { unpack( 'x4n', $_[0]->raw ) } sub padding_length { unpack( 'x6C', $_[0]->raw ) } sub type { unpack( 'xC', $_[0]->raw ) } sub request_id { unpack( 'xxn', $_[0]->raw ) } __PACKAGE__->meta->make_immutable; __END__ =head1 NAME FCGI::Client::RecordHeader - record header object for FCGI =head1 SYNOPSIS my $header = FCGI::Client::RecordHeader->new(raw => $raw); say $header->type; =head1 DESCRIPTION This module is record header class for L. =head1 ATTRIBUTES =over 4 =item raw the raw string of record header. size of record header is defined at L. =back =head1 INSTANCE METHOD =over 4 =item $self->request_id() =item $self->type() =item $self->content_length() =item $self->padding_length() These methods returns each field of record header. =back =head1 SEE ALSO L minil.toml100664001751001751 17713323125150 16665 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09name = "FCGI-Client" # badges = ["travis"] authority="cpan:TOKUHIROM" module_maker="ModuleBuildTiny" static_install = "auto" fcgicli.pl100775001751001751 224713323125150 20327 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/scripts#!/usr/bin/perl use strict; use warnings; use Pod::Usage; use Getopt::Long; use FCGI::Client; use IO::Socket::INET; GetOptions( 'h|help' => \my $help, ) or pod2usage(); pod2usage() if $help; pod2usage() if @ARGV < 1; my ($fcgi_file, $query_string) = @ARGV; &main;exit; sub main { my $srvsock = IO::Socket::INET->new( LocalPort => 0, Listen => 1, ) or die $!; defined( my $kid = fork ) or die "Cannot fork - $!"; if( $kid == 0 ) { open STDIN, "<&", $srvsock; close STDOUT; exec( $fcgi_file ); die "Cannot exec $fcgi_file - $!"; } my $sock = IO::Socket::INET->new( PeerHost => $srvsock->sockhost, PeerPort => $srvsock->sockport, ) or die $!; my $client = FCGI::Client::Connection->new( sock => $sock ); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => $query_string || '', }, '' ); print STDERR $stderr if $stderr; print $stdout; } __END__ =head1 NAME fcgicli.pl - =head1 SYNOPSIS $ fcgicli.pl foo.fcgi [foo=bar&hoge=fuga] =head1 AUTHOR Paul Evans Tokuhiro Matsuno 00_compile.t100664001751001751 11013323125150 17222 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/tuse strict; use Test::More tests => 1; BEGIN { use_ok 'FCGI::Client' } big_post.fcgi100775001751001751 47413323125150 20476 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi#!/usr/bin/env perl use FCGI; my $req = FCGI::Request(); while ($req->Accept() >= 0) { my $read = read(STDIN, my $buf, $ENV{CONTENT_LENGTH}) or die $!; print STDERR "len: $read, $ENV{CONTENT_LENGTH}\n"; print("Content−Type: $ENV{CONTENT_TYPE}\r\nContent-Length: $ENV{CONTENT_LENGTH}\r\n\r\n$buf"); } fcgi.rb100664001751001751 3451713323125150 17335 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi=begin fcgi.rb 0.9.2 - fcgi.so compatible pure-ruby FastCGI library fastcgi.rb Copyright (C) 2001 Eli Green fcgi.rb Copyright (C) 2002-2003 MoonWolf fcgi.rb Copyright (C) 2004 Minero Aoki fcgi.rb Copyright (C) 2011 saks and Julik Tarkhanov fcgi.rb Copyright (C) 2012-2013 mva =end trap('SIGTERM') { exit } trap('SIGPIPE','IGNORE') begin raise LoadError if ENV["USE_PURE_RUBY_FCGI"] require "fcgi.so" rescue LoadError # Load the pure ruby version instead # At this point we do have STDERR so put it to some good use $stderr.puts "Your FCGI gem does not contain the FCGI shared library, running pure ruby instead" require 'socket' require 'stringio' class FCGI def self.is_cgi? begin s = Socket.for_fd($stdin.fileno) s.getpeername false rescue Errno::ENOTCONN false rescue Errno::ENOTSOCK, Errno::EINVAL true end end def self.each(&block) f = default_connection() Server.new(f).each_request(&block) ensure f.close if f end def self.each_request(&block) f = default_connection() Server.new(f).each_request(&block) ensure f.close if f end def self.default_connection ::Socket.for_fd($stdin.fileno) end ProtocolVersion = 1 # Record types FCGI_BEGIN_REQUEST = 1 FCGI_ABORT_REQUEST = 2 FCGI_END_REQUEST = 3 FCGI_PARAMS = 4 FCGI_STDIN = 5 FCGI_STDOUT = 6 FCGI_STDERR = 7 FCGI_DATA = 8 FCGI_GET_VALUES = 9 FCGI_GET_VALUES_RESULT = 10 FCGI_UNKNOWN_TYPE = 11 FCGI_MAXTYPE = FCGI_UNKNOWN_TYPE FCGI_NULL_REQUEST_ID = 0 # FCGI_BEGIN_REQUSET.role FCGI_RESPONDER = 1 FCGI_AUTHORIZER = 2 FCGI_FILTER = 3 # FCGI_BEGIN_REQUEST.flags FCGI_KEEP_CONN = 1 # FCGI_END_REQUEST.protocolStatus FCGI_REQUEST_COMPLETE = 0 FCGI_CANT_MPX_CONN = 1 FCGI_OVERLOADED = 2 FCGI_UNKNOWN_ROLE = 3 class Server def initialize(server) @server = server @buffers = {} @default_parameters = { "FCGI_MAX_CONNS" => 1, "FCGI_MAX_REQS" => 1, "FCGI_MPX_CONNS" => true } end def each_request(&block) graceful = false trap("SIGUSR1") { graceful = true } while true begin session(&block) rescue Errno::EPIPE, EOFError # HTTP request is canceled by the remote user end exit 0 if graceful end end def session sock, _ = *@server.accept return unless sock fsock = FastCGISocket.new(sock) req = next_request(fsock) yield req respond_to req, fsock, FCGI_REQUEST_COMPLETE ensure sock.close if sock and not sock.closed? end private def next_request(sock) while rec = sock.read_record if rec.management_record? case rec.type when FCGI_GET_VALUES sock.send_record handle_GET_VALUES(rec) else sock.send_record UnknownTypeRecord.new(rec.request_id, rec.type) end else case rec.type when FCGI_BEGIN_REQUEST @buffers[rec.request_id] = RecordBuffer.new(rec) when FCGI_ABORT_REQUEST raise "got ABORT_REQUEST" # FIXME else buf = @buffers[rec.request_id] or next # inactive request buf.push rec if buf.ready? @buffers.delete rec.request_id return buf.new_request end end end end raise "must not happen: FCGI socket unexpected EOF" end def handle_GET_VALUES(rec) h = {} rec.values.each_key do |name| h[name] = @default_parameters[name] end ValuesRecord.new(FCGI_GET_VALUES_RESULT, rec.request_id, h) end def respond_to(req, sock, status) split_data(FCGI_STDOUT, req.id, req.out) do |rec| sock.send_record rec end split_data(FCGI_STDERR, req.id, req.err) do |rec| sock.send_record rec end if req.err.length > 0 sock.send_record EndRequestRecord.new(req.id, 0, status) end DATA_UNIT = 16384 def split_data(type, id, f) unless f.length == 0 f.rewind while s = f.read(DATA_UNIT) yield GenericDataRecord.new(type, id, s) end end yield GenericDataRecord.new(type, id, '') end end class FastCGISocket def initialize(sock) @socket = sock end def read_record header = @socket.read(Record::HEADER_LENGTH) or return nil return nil unless header.size == Record::HEADER_LENGTH _, type, reqid, clen, padlen, _ = *Record.parse_header(header) Record.class_for(type).parse(reqid, read_record_body(clen, padlen)) end def read_record_body(clen, padlen) buf = '' while buf.length < clen buf << @socket.read([1024, clen - buf.length].min) end @socket.read padlen if padlen buf end private :read_record_body def send_record(rec) @socket.write rec.serialize @socket.flush end end class RecordBuffer def initialize(rec) @begin_request = rec @envs = [] @stdins = [] @datas = [] end def push(rec) case rec when ParamsRecord @envs.push rec when StdinDataRecord @stdins.push rec when DataRecord @datas.push rec else raise "got unknown record: #{rec.class}" end end def ready? case @begin_request.role when FCGI_RESPONDER completed?(@envs) and completed?(@stdins) when FCGI_AUTHORIZER completed?(@envs) when FCGI_FILTER completed?(@envs) and completed?(@stdins) and completed?(@datas) else raise "unknown role: #{@begin_request.role}" end end def completed?(records) records.last and records.last.empty? end private :completed? def new_request Request.new(@begin_request.request_id, env(), stdin(), nil, nil, data()) end def env h = {} @envs.each {|rec| h.update rec.values } h end def stdin StringIO.new(@stdins.inject('') {|buf, rec| buf << rec.flagment }) end def data StringIO.new(@datas.inject('') {|buf, rec| buf << rec.flagment }) end end class Request def initialize(id, env, stdin, stdout = nil, stderr = nil, data = nil) @id = id @env = env @in = stdin @out = stdout || StringIO.new @err = stderr || StringIO.new @data = data || StringIO.new end attr_reader :id attr_reader :env attr_reader :in attr_reader :out attr_reader :err attr_reader :data def finish # for backword compatibility end end class Record # uint8_t protocol_version; # uint8_t record_type; # uint16_t request_id; (big endian) # uint16_t content_length; (big endian) # uint8_t padding_length; # uint8_t reserved; HEADER_FORMAT = 'CCnnCC' HEADER_LENGTH = 8 def self.parse_header(buf) return *buf.unpack(HEADER_FORMAT) end def self.class_for(type) RECORD_CLASS[type] end def initialize(type, reqid) @type = type @request_id = reqid end def version ::FCGI::ProtocolVersion end attr_reader :type attr_reader :request_id def management_record? @request_id == FCGI_NULL_REQUEST_ID end def serialize body = make_body() padlen = body.length % 8 header = make_header(body.length, padlen) header + body + "\000" * padlen end private def make_header(clen, padlen) [version(), @type, @request_id, clen, padlen, 0].pack(HEADER_FORMAT) end end class BeginRequestRecord < Record # uint16_t role; (big endian) # uint8_t flags; # uint8_t reserved[5]; BODY_FORMAT = 'nCC5' def BeginRequestRecord.parse(id, body) role, flags, *_ = *body.unpack(BODY_FORMAT) new(id, role, flags) end def initialize(id, role, flags) super FCGI_BEGIN_REQUEST, id @role = role @flags = flags end attr_reader :role attr_reader :flags def make_body [@role, @flags, 0, 0, 0, 0, 0].pack(BODY_FORMAT) end end class AbortRequestRecord < Record def AbortRequestRecord.parse(id, body) new(id) end def initialize(id) super FCGI_ABORT_REQUEST, id end end class EndRequestRecord < Record # uint32_t appStatus; (big endian) # uint8_t protocolStatus; # uint8_t reserved[3]; BODY_FORMAT = 'NCC3' def self.parse(id, body) appstatus, protostatus, *reserved = *body.unpack(BODY_FORMAT) new(id, appstatus, protostatus) end def initialize(id, appstatus, protostatus) super FCGI_END_REQUEST, id @application_status = appstatus @protocol_status = protostatus end attr_reader :application_status attr_reader :protocol_status private def make_body [@application_status, @protocol_status, 0, 0, 0].pack(BODY_FORMAT) end end class UnknownTypeRecord < Record # uint8_t type; # uint8_t reserved[7]; BODY_FORMAT = 'CC7' def self.parse(id, body) type, *reserved = *body.unpack(BODY_FORMAT) new(id, type) end def initialize(id, t) super FCGI_UNKNOWN_TYPE, id @unknown_type = t end attr_reader :unknown_type private def make_body [@unknown_type, 0, 0, 0, 0, 0, 0, 0].pack(BODY_FORMAT) end end class ValuesRecord < Record def self.parse(id, body) new(id, parse_values(body)) end def self.parse_values(buf) result = {} until buf.empty? name, value = *read_pair(buf) result[name] = value end result end def self.read_pair(buf) nlen = read_length(buf) vlen = read_length(buf) [buf.slice!(0, nlen), buf.slice!(0, vlen)] end if "".respond_to?(:bytes) # Ruby 1.9 string semantics def self.read_length(buf) if buf[0].bytes.first >> 7 == 0 buf.slice!(0,1)[0].bytes.first else buf.slice!(0,4).unpack('N')[0] & ((1<<31) - 1) end end else # Ruby 1.8 string def self.read_length(buf) if buf[0] >> 7 == 0 buf.slice!(0,1)[0].bytes.first else buf.slice!(0,4).unpack('N')[0] & ((1<<31) - 1) end end end def initialize(type, id, values) super type, id @values = values end attr_reader :values private def make_body buf = '' @values.each do |name, value| buf << serialize_length(name.length) buf << serialize_length(value.length) buf << name buf << value end buf end def serialize_length(len) if len < 0x80 then len.chr else [len | (1<<31)].pack('N') end end end class GetValuesRecord < ValuesRecord def initialize(id, values) super FCGI_GET_VALUES, id, values end end class ParamsRecord < ValuesRecord def initialize(id, values) super FCGI_PARAMS, id, values end def empty? @values.empty? end end class GenericDataRecord < Record def self.parse(id, body) new(id, body) end def initialize(type, id, flagment) super type, id @flagment = flagment end attr_reader :flagment def empty? @flagment.empty? end private def make_body if @flagment.respond_to? 'force_encoding' then return @flagment.dup.force_encoding('BINARY') else return @flagment end end end class StdinDataRecord < GenericDataRecord def initialize(id, flagment) super FCGI_STDIN, id, flagment end end class StdoutDataRecord < GenericDataRecord def initialize(id, flagment) super FCGI_STDOUT, id, flagment end end class DataRecord < GenericDataRecord def initialize(id, flagment) super FCGI_DATA, id, flagment end end class Record # redefine RECORD_CLASS = { FCGI_GET_VALUES => GetValuesRecord, FCGI_BEGIN_REQUEST => BeginRequestRecord, FCGI_ABORT_REQUEST => AbortRequestRecord, FCGI_PARAMS => ParamsRecord, FCGI_STDIN => StdinDataRecord, FCGI_DATA => DataRecord, FCGI_STDOUT => StdoutDataRecord, FCGI_END_REQUEST => EndRequestRecord } end end # FCGI class end # begin # There is no C version of 'each_cgi' # Note: for ruby-1.6.8 at least, the constants CGI_PARAMS/CGI_COOKIES # are defined within module 'CGI', even if you have subclassed it class FCGI def self.each_cgi(*args) require 'cgi' eval(<<-EOS,TOPLEVEL_BINDING) class CGI public :env_table def self.remove_params if (const_defined?(:CGI_PARAMS)) remove_const(:CGI_PARAMS) remove_const(:CGI_COOKIES) end end end # ::CGI class class FCGI class CGI < ::CGI def initialize(request, *args) ::CGI.remove_params @request = request super(*args) @args = *args end def args @args end def env_table @request.env end def stdinput @request.in end def stdoutput @request.out end end # FCGI::CGI class end # FCGI class EOS if FCGI::is_cgi? yield ::CGI.new(*args) else FCGI::each do |request| $stdout, $stderr = request.out, request.err yield CGI.new(request, *args) request.finish end end end end hello.fcgi100775001751001751 31013323125150 17760 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi#!/usr/bin/env perl use FCGI; my $req = FCGI::Request(); while ($req->Accept() >= 0) { print STDERR "hello, stderr\n"; print("Content−type: text/html\r\n\r\nhello\n$ENV{QUERY_STRING}"); } keepalive.fcgi100775001751001751 32513323125150 20630 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi#!/usr/bin/perl use FCGI; my %env; my $req = FCGI::Request(\*STDIN, \*STDOUT, \*STDOUT, \%env, 0, &FCGI::FAIL_ACCEPT_ON_INTR); while ($req->Accept() >= 0) { print("Content−type: text/html\r\n\r\nhello"); } post.fcgi100775001751001751 25713323125150 17654 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi#!/usr/bin/env perl use FCGI; my $req = FCGI::Request(); while ($req->Accept() >= 0) { my $line = ; print("Content−type: text/html\r\n\r\nhello: $line"); } ruby.rb100775001751001751 30413323125150 17334 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi#!/usr/bin/ruby # encoding: utf-8 load 't/fcgi/fcgi.rb' FCGI.each {|f| f.err.print("hello, stderr\n") f.out.print("Content−type: text/html\r\n\r\nhello\n#{ f.env['QUERY_STRING'] }") } timeout.fcgi100775001751001751 15113323125150 20346 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/fcgi#!/usr/bin/env perl use FCGI; my $req = FCGI::Request(); while ($req->Accept() >= 0) { sleep 60; } Internal.pm100664001751001751 340013323125150 20256 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/t/lib/tpackage t::Internal; use FCGI::Client::Constant; use File::Temp (); use autodie; use HTTP::Request; use IO::Socket::UNIX; use FCGI::Client::RecordFactory; use FCGI::Client::Record; use FCGI::Client::Connection; use Time::HiRes 'sleep'; use Types::Standard qw/Str Int/; use Moo; has path => ( is => 'ro', isa => Str ); has sock_path => ( is => 'ro', isa => Str, lazy => 1, default => sub { File::Temp::tmpnam() }, ); has child_pid => ( is => 'rw', isa => Int, lazy => 1, default => sub { my $self = shift; my $path = $self->sock_path; # generate common path before fork(2) my $pid = fork(); if ( $pid > 0 ) { # parent return $pid; } else { my $sock = IO::Socket::UNIX->new( Local => $path, Listen => 30, ) or die $!; open *STDIN, '>&', $sock; # dup(2) exec $self->path; die "should not reach here: $!"; } } ); no Moo; sub DEMOLISH { my $self = shift; if ($self->child_pid) { kill 'TERM' => $self->child_pid; wait; } unlink $self->sock_path; } sub create_socket { my $self = shift; $self->child_pid(); # invoke child my $path = $self->sock_path; my $retry = 30; while ($retry-- >= 0) { my $sock = IO::Socket::UNIX->new( Peer => $path, ); return $sock if $sock; sleep 0.3; } die "cannot open socket $path: $!"; } sub request { my ($self, $env, $content, $timeout) = @_; my $con = FCGI::Client::Connection->new(sock => $self->create_socket, timeout => $timeout || 1); return $con->request($env, $content); } __PACKAGE__->meta->make_immutable; 00_hello.t100664001751001751 60113323125150 20411 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use lib 't/lib/'; use t::Internal; my $client = t::Internal->new(path => 't/fcgi/hello.fcgi'); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', }, '' ); is $stdout, "Content−type: text/html\r\n\r\nhello\nfoo=bar"; is $stderr, "hello, stderr\n"; done_testing; 02_ruby.t100664001751001751 57613323125150 20304 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use lib 't/lib/'; use t::Internal; my $client = t::Internal->new(path => 't/fcgi/ruby.rb'); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', }, '' ); is $stdout, "Content−type: text/html\r\n\r\nhello\nfoo=bar"; is $stderr, "hello, stderr\n"; done_testing; 03_post.t100664001751001751 57013323125150 20303 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use lib 't/lib/'; use t::Internal; my $client = t::Internal->new(path => 't/fcgi/post.fcgi'); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'POST', QUERY_STRING => 'foo=bar', }, "wow\n" ); is $stdout, "Content−type: text/html\r\n\r\nhello: wow\n"; is $stderr, undef; done_testing; 04_external.t100664001751001751 211713323125150 21160 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use Test::TCP; use FCGI; use FCGI::Client::Connection; test_tcp( client => sub { my $port = shift; my $sock = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => $port, ) or die $!; my $client = FCGI::Client::Connection->new(sock => $sock); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', }, '' ); is $stdout, "Content−type: text/html\r\n\r\nhello external world"; done_testing; }, server => sub { my $port = shift; my %env; my $sock = FCGI::OpenSocket(':'.$port, 100) or die; my $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDOUT, \%env, $sock, &FCGI::FAIL_ACCEPT_ON_INTR, ); while ($request->Accept >= 0) { print("Content−type: text/html\r\n\r\nhello external world"); } }, ); 05_long_key_names_values.t100664001751001751 67413323125150 23676 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use lib 't/lib/'; use t::Internal; my $client = t::Internal->new(path => 't/fcgi/hello.fcgi'); my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=' . ('0' x 125), 'HTTP_X_FOO' . ('0' x 125) => 1, }, '' ); is $stdout, "Content−type: text/html\r\n\r\nhello\nfoo=".('0'x125); is $stderr, "hello, stderr\n"; done_testing; 06_big_post.t100664001751001751 132513323125150 21146 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use lib 't/lib/'; use t::Internal; my $client = t::Internal->new(path => 't/fcgi/big_post.fcgi'); for my $len (85_556, 1_000_000) { my $chunk = "abcdefg" x $len; my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', CONTENT_TYPE => 'application/octet-stream', CONTENT_LENGTH => length($chunk), }, $chunk, 10 ); is $stdout, "Content−Type: application/octet-stream\r\nContent-Length: @{[ length($chunk) ]}\r\n\r\n$chunk"; my ($x1, $x2) = $stderr =~ /len: (\d+), (\d+)\n/; is $x1, $x2; is $x1, length($chunk); } done_testing; 07_timeout.t100664001751001751 55413323125150 21012 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xt/010_liveuse strict; use warnings; use Test::More; use lib 't/lib/'; use t::Internal; my $client = t::Internal->new(path => 't/fcgi/timeout.fcgi'); eval { my ( $stdout, $stderr ) = $client->request( +{ REQUEST_METHOD => 'GET', QUERY_STRING => 'foo=bar', }, '' ); }; like $@ => qr/REQUEST_TIME_OUT/; done_testing; 02_perlcritic.t100664001751001751 70113323125150 20132 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09/xtuse strict; use Test::More; eval q{ use Test::Perl::Critic 1.02 -exclude => [ 'Subroutines::ProhibitSubroutinePrototypes', 'Subroutines::ProhibitExplicitReturnUndef', 'TestingAndDebugging::ProhibitNoStrict', 'ControlStructures::ProhibitMutatingListFunctions', 'InputOutput::RequireEncodingWithUTF8Layer', ] }; plan skip_all => "Test::Perl::Critic 1.02+ is not installed." if $@; all_critic_ok('lib'); META.yml100664001751001751 262213323125150 16146 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09--- abstract: 'client library for fastcgi protocol' author: - 'Tokuhiro Matsuno ' build_requires: Test::More: '0' configure_requires: Module::Build::Tiny: '0.035' dynamic_config: 0 generated_by: 'Minilla/v3.0.9, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: FCGI-Client no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: FCGI::Client: file: lib/FCGI/Client.pm version: '0.09' FCGI::Client::Connection: file: lib/FCGI/Client/Connection.pm FCGI::Client::Constant: file: lib/FCGI/Client/Constant.pm FCGI::Client::Record: file: lib/FCGI/Client/Record.pm FCGI::Client::RecordFactory: file: lib/FCGI/Client/RecordFactory.pm FCGI::Client::RecordHeader: file: lib/FCGI/Client/RecordHeader.pm requires: IO::Socket::UNIX: '0' Moo: '2' Type::Tiny: '0' perl: '5.008001' resources: bugtracker: https://github.com/tokuhirom/p5-fcgi-client/issues homepage: https://github.com/tokuhirom/p5-fcgi-client repository: git://github.com/tokuhirom/p5-fcgi-client.git version: '0.09' x_authority: cpan:TOKUHIROM x_contributors: - 'Peter Keen ' - 'Tokuhiro Matsuno ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' MANIFEST100664001751001751 117213323125150 16025 0ustar00tokuhiromtokuhirom000000000000FCGI-Client-0.09Build.PL Changes LICENSE META.json README.md cpanfile lib/FCGI/Client.pm lib/FCGI/Client/Connection.pm lib/FCGI/Client/Constant.pm lib/FCGI/Client/Record.pm lib/FCGI/Client/RecordFactory.pm lib/FCGI/Client/RecordHeader.pm minil.toml scripts/fcgicli.pl t/00_compile.t t/fcgi/big_post.fcgi t/fcgi/fcgi.rb t/fcgi/hello.fcgi t/fcgi/keepalive.fcgi t/fcgi/post.fcgi t/fcgi/ruby.rb t/fcgi/timeout.fcgi t/lib/t/Internal.pm xt/010_live/00_hello.t xt/010_live/02_ruby.t xt/010_live/03_post.t xt/010_live/04_external.t xt/010_live/05_long_key_names_values.t xt/010_live/06_big_post.t xt/010_live/07_timeout.t xt/02_perlcritic.t META.yml MANIFEST