/t/020_interface/cgi.t

http://github.com/http-engine/HTTP-Engine · Raku · 61 lines · 51 code · 10 blank · 0 comment · 0 complexity · 955547df9b6b9d04faf83d23bc6539e5 MD5 · raw file

  1. use strict;
  2. use warnings;
  3. use HTTP::Engine;
  4. use HTTP::Engine::Interface::CGI;
  5. use IO::Scalar;
  6. use Test::Base;
  7. tie *STDOUT, 'IO::Scalar', \my $out;
  8. tie *STDIN, 'IO::Scalar', \my $in;
  9. plan tests => 1*blocks;
  10. filters {
  11. env => [qw/yaml/],
  12. response => [qw/chop crlf/],
  13. };
  14. run {
  15. my $block = shift;
  16. local %ENV = %{$block->env};
  17. HTTP::Engine->new(
  18. interface => {
  19. module => 'CGI',
  20. args => { },
  21. request_handler => sub {
  22. my $req = shift;
  23. HTTP::Engine::Response->new(
  24. status => 200,
  25. headers => HTTP::Headers::Fast->new( 'X-Req-Base' => $req->base, ),
  26. body => 'OK!',
  27. );
  28. },
  29. },
  30. )->run;
  31. is $out, $block->response(), 'response';
  32. };
  33. sub crlf {
  34. my $in = shift;
  35. $in =~ s/\n/\r\n/g;
  36. $in;
  37. }
  38. __END__
  39. ===
  40. --- env
  41. REMOTE_ADDR: 127.0.0.1
  42. SERVER_PORT: 80
  43. QUERY_STRING: ''
  44. REQUEST_METHOD: 'GET'
  45. HTTP_HOST: localhost
  46. --- response
  47. Content-Length: 3
  48. Content-Type: text/html
  49. Status: 200
  50. X-Req-Base: http://localhost/
  51. OK!