[nginx-tests] Tests: basic tests for SSL_sendfile() usage.
Maxim Dounin
mdounin at mdounin.ru
Fri Jan 30 10:36:20 UTC 2026
details: http://freenginx.org/hg/nginx-tests/rev/873c967f713d
branches:
changeset: 2039:873c967f713d
user: Maxim Dounin <mdounin at mdounin.ru>
date: Fri Jan 30 13:23:25 2026 +0300
description:
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.
diffstat:
ssl_sendfile.t | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
diffs (93 lines):
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