[nginx-tests] Tests: improved SCGI request body tests.
Maxim Dounin
mdounin at mdounin.ru
Mon May 18 00:43:04 UTC 2026
details: http://freenginx.org/hg/nginx-tests/rev/ec886195a369
branches:
changeset: 2054:ec886195a369
user: Maxim Dounin <mdounin at mdounin.ru>
date: Mon May 18 03:41:13 2026 +0300
description:
Tests: improved SCGI request body tests.
diffstat:
scgi_body.t | 49 +++++++++++++++++++++++--------------------------
1 files changed, 23 insertions(+), 26 deletions(-)
diffs (82 lines):
diff --git a/scgi_body.t b/scgi_body.t
--- a/scgi_body.t
+++ b/scgi_body.t
@@ -2,7 +2,7 @@
# (C) Maxim Dounin
-# Test for scgi backend with chunked request body.
+# Test for scgi backend with request body.
###############################################################################
@@ -57,32 +57,13 @@ EOF
###############################################################################
-like(http_get('/'), qr/X-Body: /, 'scgi no body');
-
-like(http_get_length('/', ''), qr/X-Body: /, 'scgi empty body');
-like(http_get_length('/', 'foobar'), qr/X-Body: foobar/, 'scgi body');
-
-like(http(<<EOF), qr/X-Body: foobar/, 'scgi chunked');
-GET / HTTP/1.1
-Host: localhost
-Connection: close
-Transfer-Encoding: chunked
+like(http_get('/'), qr/X-Body: ''/, 'scgi no body');
-6
-foobar
-0
-
-EOF
+like(http_get_length('/', 'foobar'), qr/X-Body: 'foobar'/, 'scgi body');
+like(http_get_length('/', ''), qr/X-Body: ''/, 'scgi empty body');
-like(http(<<EOF), qr/X-Body: /, 'scgi empty chunked');
-GET / HTTP/1.1
-Host: localhost
-Connection: close
-Transfer-Encoding: chunked
-
-0
-
-EOF
+like(http_get_chunked('/', 'foobar'), qr/X-Body: 'foobar'/, 'scgi chunked');
+like(http_get_chunked('/', ''), qr/X-Body: ''/, 'scgi empty chunked');
###############################################################################
@@ -99,6 +80,22 @@ Content-Length: $length
EOF
}
+sub http_get_chunked {
+ my ($url, $body) = @_;
+ my $length = sprintf("%x", length $body);
+ return http(<<EOF);
+GET $url HTTP/1.1
+Host: localhost
+Connection: close
+Transfer-Encoding: chunked
+
+$length
+$body
+0
+
+EOF
+}
+
###############################################################################
sub scgi_daemon {
@@ -123,7 +120,7 @@ sub scgi_daemon {
$request->connection()->print(<<EOF);
Location: http://localhost/redirect
Content-Type: text/html
-X-Body: $body
+X-Body: '$body'
SEE-THIS
EOF
More information about the nginx-devel
mailing list