unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/6] t/www_static: ensure If-Modified-Since handling works
Date: Mon, 30 Sep 2024 21:30:05 +0000	[thread overview]
Message-ID: <20240930213008.4014512-4-e@80x24.org> (raw)
In-Reply-To: <20240930213008.4014512-1-e@80x24.org>

We've had If-Modified-Since to reduce client traffic for a
while, so ensure it's tested properly and continues to work
in the future.
---
 t/www_static.t | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/t/www_static.t b/t/www_static.t
index b1181cab..8fb86a82 100644
--- a/t/www_static.t
+++ b/t/www_static.t
@@ -109,6 +109,42 @@ $client = sub {
 	IO::Uncompress::Gunzip::gunzip(\$in => \$out);
 	like($out, qr/\A<html>/, 'got HTML start after gunzip');
 	like($out, qr{</html>$}, 'got HTML end after gunzip');
+	unlink "$tmpdir/dir/foo.gz";
+	$get = GET('/dir/foo');
+
+	require HTTP::Date;
+	HTTP::Date->import('time2str');
+	$get->header('If-Modified-Since' => time2str(0));
+	$res = $cb->($get);
+	is $res->code, 304, '304 on If-Modified-Since hit';
+	$get->header('If-Modified-Since' => time2str(1));
+	$res = $cb->($get);
+	is $res->code, 200, '200 on If-Modified-Since miss';
+SKIP: {
+	# validating with curl ensures we didn't carry the same
+	# misunderstandings across both the code being tested
+	# and the test itself.
+	$ENV{TEST_EXPENSIVE} or
+		skip 'TEST_EXPENSIVE unset for validation w/curl', 1;
+	my $uri = $ENV{PLACK_TEST_EXTERNALSERVER_URI} or
+		skip 'curl test skipped w/o external server', 1;
+	my $dst = "$tmpdir/foo.dst";
+	my $dst2 = "$dst.2";
+	$uri .= '/dir/foo';
+	state $curl = require_cmd 'curl', 1;
+	xsys_e $curl, '-gsSfR', '-o', $dst, $uri;
+	xsys_e [ $curl, '-vgsSfR', '-o', $dst2, $uri, '-z', $dst ],
+		undef, { 2 => \(my $curl_err) };
+	like $curl_err, qr! HTTP/1\.[012] 304 !sm,
+		'got 304 response w/ If-Modified-Since';
+	is -s $dst2, undef, 'nothing downloaded on 304';
+	utime 1, 1, "$tmpdir/dir/foo";
+	xsys_e [ $curl, '-vgsSfR', '-o', $dst2, $uri, '-z', $dst ],
+		undef, { 2 => \$curl_err };
+	is -s $dst2, -s $dst, 'got 200 on If-Modified-Since mismatch';
+	like $curl_err, qr! HTTP/1\.[012] 200 !sm,
+		'got 200 response w/ If-Modified-Since';
+} # SKIP
 	remove_tree "$tmpdir/dir";
 };
 

  parent reply	other threads:[~2024-09-30 21:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 21:30 [PATCH 0/6] test updates + coderepo removal workaround Eric Wong
2024-09-30 21:30 ` [PATCH 1/6] t/www_static: modernize test Eric Wong
2024-09-30 21:30 ` [PATCH 2/6] t/www_static: test with our -httpd server, too Eric Wong
2024-09-30 21:30 ` Eric Wong [this message]
2024-09-30 21:30 ` [PATCH 4/6] www: improve handling of missing coderepos Eric Wong
2024-09-30 21:30 ` [PATCH 5/6] xt/solver: use `psgi' shortcut for require_mods() Eric Wong
2024-09-30 21:30 ` [PATCH 6/6] t/{config,solver_git}: simplify error handling Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240930213008.4014512-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).