changeset 3:d7b8639a8857

Tests for "proxy_request_buffering off".
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 09 Feb 2015 16:33:13 +0300
parents 04788ce8dae7
children 01a36878bf36
files t/buffering.t
diffstat 1 files changed, 93 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/buffering.t	Mon Feb 09 16:33:13 2015 +0300
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Tests for "proxy_request_buffering off".
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+use Test::Nginx;
+
+use Socket qw/ CRLF /;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(1)
+	->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+    %%TEST_GLOBALS_HTTP%%
+
+    server {
+        listen       127.0.0.1:8080;
+        server_name  localhost;
+
+        location / {
+            proxy_pass http://127.0.0.1:8080/catch;
+            proxy_request_buffering off;
+            add_header X-Request-Time $request_time always;
+        }
+
+        location /catch {
+            proxy_pass http://127.0.0.1:8080/proxy;
+            proxy_request_buffering off;
+            catch_body on;
+        }
+
+        location /proxy {
+            proxy_pass http://127.0.0.1:8080/empty;
+        }
+
+        location /empty {
+            return 200 "test response body\n";
+        }
+    }
+}
+
+EOF
+
+$t->write_file('index.html', 'SEE-THIS');
+$t->run();
+
+###############################################################################
+
+# buffering switched off - expect immediate reject,
+# before we'll send second part of the body
+
+like(get_sleep('/', '12345X', '123456'),
+	qr/403 Forbidden.*X-Request-Time: 0/ms,
+	'unbuffered request rejected');
+
+###############################################################################
+
+sub get_sleep {
+	my $uri = shift;
+	my $first = shift;
+	my $second = shift;
+	my $length = length($first) + length($second);
+	return http(
+		"GET $uri HTTP/1.1" . CRLF
+		. "Host: localhost" . CRLF
+		. "Connection: close" . CRLF
+		. "Content-Length: $length" . CRLF . CRLF
+		. $first,
+		sleep => 1.1,
+		body => $second
+	);
+}
+
+###############################################################################