[PATCH] Tests: added Expires and Cache-Control headers test
Vadim Fedorenko
vadim.fedorenko at cdnnow.ru
Thu Apr 14 23:03:40 UTC 2022
# HG changeset patch
# User Vadim Fedorenko <vadim.fedorenko at cdnnow.ru>
# Date 1649976970 -10800
# Fri Apr 15 01:56:10 2022 +0300
# Node ID 39dea3973d47e0bcd226beb3c6554dcdc0e26495
# Parent 0c50a00e67334659d58d3cf7cb81fcf5872a8285
Tests: added Expires and Cache-Control headers test
diff -r 0c50a00e6733 -r 39dea3973d47 proxy_cache_expires_cache_control.t
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/proxy_cache_expires_cache_control.t Fri Apr 15 01:56:10 2022 +0300
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+
+# (C) Georgii Dzebisashvili
+
+# Tests for cache management regarding https://trac.nginx.org/nginx/ticket/964
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+use File::Find;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $scriptDir = $FindBin::Bin;
+my $cacheDir = $scriptDir."/testcache";
+my $tempDir = $scriptDir."/testtemp";
+
+my $t = Test::Nginx->new()->plan(5)->write_file_expand('nginx.conf', <<"EOF");
+
+error_log stderr info;
+daemon off;
+events {
+ worker_connections 64;
+}
+http {
+ access_log off;
+ proxy_cache_path $cacheDir levels=2 keys_zone=cache_zone:1m inactive=24h max_size=10m;
+ proxy_temp_path $tempDir;
+ server {
+ listen 127.0.0.1:8080;
+ location / {
+ proxy_pass http://127.0.0.2:8080;
+ proxy_cache cache_zone;
+ }
+ }
+ server {
+ listen 127.0.0.2:8080;
+ location /success {
+ add_header Cache-Control "max-age=3600";
+ add_header Expires "Tue, 15 Nov 1994 12:45:26 GMT";
+ return 200 "Hello world!";
+ }
+ location /fail {
+ add_header Expires "Tue, 15 Nov 1994 12:45:26 GMT";
+ add_header Cache-Control "max-age=3600";
+ return 200 "Hello world!";
+ }
+ }
+}
+
+
+EOF
+
+$t->run();
+
+###############################################################################
+
+my $counter = 0;
+
+sub fileMatchCallback {
+ -f && $counter++; # Only count files
+}
+
+my $r;
+
+$r = http_get('/success');
+like($r, qr/Cache-Control/, 'cache-control-first-cache-control-is-present');
+like($r, qr/Expires/, 'cache-control-first-expires-is-present');
+
+$r = http_get('/fail');
+like($r, qr/Cache-Control/, 'expires-first-cache-control-is-present');
+like($r, qr/Expires/, 'expires-first-expires-is-present');
+
+find(\&fileMatchCallback, $cacheDir);
+
+is($counter, 2, 'overall number of cached requests');
More information about the nginx-devel
mailing list