/examples/lighty/test_fastcgi.pl

http://github.com/http-engine/HTTP-Engine · Perl · 52 lines · 43 code · 8 blank · 1 comment · 0 complexity · d522d1a511b346b95332d574e19c0e58 MD5 · raw file

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use FindBin '$Bin';
  5. use HTTP::Engine;
  6. use Data::Dumper;
  7. use Getopt::Long;
  8. GetOptions(
  9. \my %option,
  10. qw/listen=s/
  11. );
  12. HTTP::Engine->new(
  13. interface => {
  14. module => 'FCGI',
  15. args => {
  16. $option{listen} ? (
  17. listen => $option{listen},
  18. nproc => 1,
  19. ) : (),
  20. },
  21. request_handler => sub {
  22. my $req = shift;
  23. my $res = HTTP::Engine::Response->new;
  24. $res->content_type('text/html');
  25. $res->body( render_body( Dumper($req) ) );
  26. $res;
  27. }
  28. },
  29. )->run;
  30. sub render_body {
  31. my @args = @_;
  32. my $body = <<"...";
  33. <form method="post">
  34. <input type="text" name="foo" />
  35. <input type="submit" />
  36. </form>
  37. <form method="post" enctype="multipart/form-data">
  38. <input type="file" name="upload_file" />
  39. <input type="submit" />
  40. </form>
  41. ...
  42. $body .= join '', map { "<pre>$_</pre>" } @args;
  43. $body;
  44. }