http_expect_100_continue.t 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for Expect: 100-continue support.
  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. my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2);
  15. $t->write_file_expand('nginx.conf', <<'EOF');
  16. %%TEST_GLOBALS%%
  17. master_process off;
  18. daemon off;
  19. events {
  20. }
  21. http {
  22. %%TEST_GLOBALS_HTTP%%
  23. server {
  24. listen 127.0.0.1:8080;
  25. server_name localhost;
  26. location / {
  27. proxy_pass http://localhost:8080/local;
  28. }
  29. location /local {
  30. }
  31. }
  32. }
  33. EOF
  34. $t->run();
  35. ###############################################################################
  36. like(http_100_request('/', '1.1'), qr/100/, 'expect 100 continue');
  37. # From RFC 2616, 8.2.3 Use of the 100 (Continue) Status:
  38. #
  39. # - An origin server SHOULD NOT send a 100 (Continue) response if
  40. # the request message does not include an Expect request-header
  41. # field with the "100-continue" expectation, and MUST NOT send a
  42. # 100 (Continue) response if such a request comes from an HTTP/1.0
  43. # (or earlier) client.
  44. unlike(http_100_request('/', '1.0'), qr/100/, 'no 100 continue via http 1.0');
  45. ###############################################################################
  46. sub http_100_request {
  47. my ($url, $version) = @_;
  48. my $r = http(<<EOF);
  49. POST $url HTTP/$version
  50. Host: localhost
  51. Expect: 100-continue
  52. Content-Length: 0
  53. Connection: close
  54. EOF
  55. }
  56. ###############################################################################