From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 311A81F5D3 for ; Mon, 30 Sep 2024 21:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1727731810; bh=r5C0w51ZQ2UYed6aHSTmOiFe0HfPb7c2Ih5yvauFaJs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oUHhiYAK26KiU6cTzWrw8TmiosXr8EIWwj630FjoHcUv7br2GEegMbCwr9BpZ7wkV M6CAp+0O/cRALPccqxSvna1Us0pgZjsyhr7dp9BIj8cPYG3qUgxxDpSWl+gS8eZtSy bzatR8DzVVnAlw3+9f2pe0Kn1rQHvSXKY8xZQGRs= From: Eric Wong 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 Message-ID: <20240930213008.4014512-4-e@80x24.org> In-Reply-To: <20240930213008.4014512-1-e@80x24.org> References: <20240930213008.4014512-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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/, 'got HTML start after gunzip'); like($out, qr{$}, '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"; };