[PATCH] Tests: basic tests for SSL_sendfile() usage

Maxim Dounin mdounin at mdounin.ru
Wed Jan 28 01:02:39 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1769562150 -10800
#      Wed Jan 28 04:02:30 2026 +0300
# Node ID 9bf525096ac997f9b8da66443377977da167838f
# Parent  d4e542b13471f41d03f99f7f71663be5a9e46f8f
Tests: basic tests for SSL_sendfile() usage.

Note that these tests assume kernel TLS enabled in OS (usually the case
now, see 7941:65946a191197 changeset for details).  If kernel TLS is not
enabled, tests will still succeed, though will use normal SSL_write()
instead.  Mostly usable with manual checking of the debug log.

diff --git a/ssl_sendfile.t b/ssl_sendfile.t
new file mode 100644
--- /dev/null
+++ b/ssl_sendfile.t
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Tests for http ssl module, SSL_sendfile() usage.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()
+	->has(qw/http http_ssl openssl:3.0.0 socket_ssl/)
+	->has_daemon('openssl')->plan(4);
+
+$t->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+    %%TEST_GLOBALS_HTTP%%
+
+    server {
+        listen       127.0.0.1:8080 sndbuf=16k;
+        listen       127.0.0.1:8443 ssl sndbuf=16k;
+        server_name  localhost;
+
+        sendfile on;
+        ssl_conf_command Options KTLS;
+
+        ssl_certificate localhost.crt;
+        ssl_certificate_key localhost.key;
+    }
+}
+
+EOF
+
+$t->write_file('openssl.conf', <<EOF);
+[ req ]
+default_bits = 2048
+encrypt_key = no
+distinguished_name = req_distinguished_name
+[ req_distinguished_name ]
+EOF
+
+my $d = $t->testdir();
+
+foreach my $name ('localhost') {
+	system('openssl req -x509 -new '
+		. "-config $d/openssl.conf -subj /CN=$name/ "
+		. "-out $d/$name.crt -keyout $d/$name.key "
+		. ">>$d/openssl.out 2>&1") == 0
+		or die "Can't create certificate for $name: $!\n";
+}
+
+$t->run();
+
+$t->write_file('small', 'SEE-THIS');
+$t->write_file('big', ('123456789' x 30000) . 'SEE-THIS');
+
+###############################################################################
+
+like(http_get('/small', SSL => 1), qr/SEE-THIS/, 'sendfile small');
+like(http_get('/big', SSL => 1, sleep => 0.5),
+	qr/^(123456789){30000}SEE-THIS$/m, 'sendfile big');
+
+like(http_get('/small'), qr/SEE-THIS/, 'sendfile plain small');
+like(http_get('/big', sleep => 0.5),
+	qr/^(123456789){30000}SEE-THIS$/m, 'sendfile plain big');
+
+###############################################################################



More information about the nginx-devel mailing list