proxy_chunked.t 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Test for http backend returning response with Transfer-Encoding: chunked.
  4. # Since nginx uses HTTP/1.0 in requests to backend it's backend bug, but we
  5. # want to handle this gracefully. And anyway chunked support will be required
  6. # for HTTP/1.1 backend connections.
  7. ###############################################################################
  8. use warnings;
  9. use strict;
  10. use Test::More;
  11. use IO::Select;
  12. BEGIN { use FindBin; chdir($FindBin::Bin); }
  13. use lib 'lib';
  14. use Test::Nginx;
  15. ###############################################################################
  16. select STDERR; $| = 1;
  17. select STDOUT; $| = 1;
  18. my $t = Test::Nginx->new()->has(qw/http proxy ssi/)->plan(3);
  19. $t->write_file_expand('nginx.conf', <<'EOF');
  20. %%TEST_GLOBALS%%
  21. master_process off;
  22. daemon off;
  23. events {
  24. }
  25. http {
  26. %%TEST_GLOBALS_HTTP%%
  27. server {
  28. listen 127.0.0.1:8080;
  29. server_name localhost;
  30. location / {
  31. proxy_pass http://127.0.0.1:8081;
  32. proxy_read_timeout 1s;
  33. }
  34. location /nobuffering {
  35. proxy_pass http://127.0.0.1:8081;
  36. proxy_read_timeout 1s;
  37. proxy_buffering off;
  38. }
  39. location /inmemory.html {
  40. ssi on;
  41. }
  42. }
  43. }
  44. EOF
  45. $t->write_file('inmemory.html',
  46. '<!--#include virtual="/" set="one" --><!--#echo var="one" -->');
  47. $t->run_daemon(\&http_chunked_daemon);
  48. $t->run();
  49. ###############################################################################
  50. {
  51. local $TODO = 'not yet';
  52. like(http_get('/'), qr/\x0d\x0aSEE-THIS$/s, 'chunked');
  53. like(http_get('/nobuffering'), qr/\x0d\x0aSEE-THIS$/s, 'chunked nobuffering');
  54. like(http_get('/inmemory.html'), qr/\x0d\x0aSEE-THIS$/s, 'chunked inmemory');
  55. }
  56. ###############################################################################
  57. sub http_chunked_daemon {
  58. my $server = IO::Socket::INET->new(
  59. Proto => 'tcp',
  60. LocalAddr => '127.0.0.1:8081',
  61. Listen => 5,
  62. Reuse => 1
  63. )
  64. or die "Can't create listening socket: $!\n";
  65. while (my $client = $server->accept()) {
  66. $client->autoflush(1);
  67. while (<$client>) {
  68. last if (/^\x0d?\x0a?$/);
  69. }
  70. print $client <<'EOF';
  71. HTTP/1.1 200 OK
  72. Connection: close
  73. Transfer-Encoding: chunked
  74. 9
  75. SEE-THIS
  76. 0
  77. EOF
  78. close $client;
  79. }
  80. }
  81. ###############################################################################