[PATCH 1 of 3] Tests: improved SCGI request body tests
Maxim Dounin
mdounin at mdounin.ru
Sat May 9 21:02:36 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1778250844 -10800
# Fri May 08 17:34:04 2026 +0300
# Node ID e5409c48dce25d4d5fe234de8a5f4f4ff9efcee7
# Parent ff476932c9806e6b8b6d9d934186fb9e43aa7aee
Tests: improved SCGI request body tests.
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