fastcgi_header_params.t 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Test for fastcgi header params.
  4. ###############################################################################
  5. use warnings;
  6. use strict;
  7. use Test::More;
  8. BEGIN { use FindBin; chdir($FindBin::Bin); }
  9. use lib 'lib';
  10. use Test::Nginx;
  11. ###############################################################################
  12. select STDERR; $| = 1;
  13. select STDOUT; $| = 1;
  14. eval { require FCGI; };
  15. plan(skip_all => 'FCGI not installed') if $@;
  16. my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(1)
  17. ->write_file_expand('nginx.conf', <<'EOF');
  18. %%TEST_GLOBALS%%
  19. master_process off;
  20. daemon off;
  21. events {
  22. }
  23. http {
  24. %%TEST_GLOBALS_HTTP%%
  25. server {
  26. listen 127.0.0.1:8080;
  27. server_name localhost;
  28. location / {
  29. fastcgi_pass 127.0.0.1:8081;
  30. fastcgi_param HTTP_X_BLAH "blah";
  31. }
  32. }
  33. }
  34. EOF
  35. $t->run_daemon(\&fastcgi_daemon);
  36. $t->run();
  37. ###############################################################################
  38. SKIP: {
  39. skip 'unsafe', 1 unless $ENV{TEST_NGINX_UNSAFE};
  40. local $TODO = 'not yet';
  41. like(http_get_headers('/'), qr/SEE-THIS/,
  42. 'fastcgi request with many ignored headers');
  43. }
  44. ###############################################################################
  45. sub http_get_headers {
  46. my ($url, %extra) = @_;
  47. return http(<<EOF, %extra);
  48. GET $url HTTP/1.0
  49. Host: localhost
  50. X-Blah: ignored header
  51. X-Blah: ignored header
  52. X-Blah: ignored header
  53. X-Blah: ignored header
  54. X-Blah: ignored header
  55. X-Blah: ignored header
  56. X-Blah: ignored header
  57. X-Blah: ignored header
  58. X-Blah: ignored header
  59. X-Blah: ignored header
  60. X-Blah: ignored header
  61. X-Blah: ignored header
  62. X-Blah: ignored header
  63. X-Blah: ignored header
  64. X-Blah: ignored header
  65. X-Blah: ignored header
  66. X-Blah: ignored header
  67. X-Blah: ignored header
  68. X-Blah: ignored header
  69. EOF
  70. }
  71. ###############################################################################
  72. sub fastcgi_daemon {
  73. my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5);
  74. my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
  75. $socket);
  76. my $count;
  77. while( $request->Accept() >= 0 ) {
  78. $count++;
  79. print <<EOF;
  80. Location: http://127.0.0.1:8080/redirect
  81. Content-Type: text/html
  82. SEE-THIS
  83. $count
  84. EOF
  85. }
  86. FCGI::CloseSocket($socket);
  87. }
  88. ###############################################################################