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 26B741F513 for ; Sun, 7 Jul 2024 05:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1720331848; bh=G1ie2/gCcAHFvGNC6LfYtr5VSY22RtSBRqpQqf0xOvI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=c4ozbXL2ZWoVbjFf6hUGZ6EJH/Md6RAZRv9CP8Co/hkU3Z7iNOQ8PC0YBP8iBUhZ5 ZrFztcdLDn/an4JEBRISlTp5hXYaxToAlIdy92I8DapH0i/Fhr88n+SRSDx2PULMht M6ovTOHMCUeIcbI8Tiie2zmaVlIzftOw5RbnaA30= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] www: manifest.js.gz handles If-Modified-Since Date: Sun, 7 Jul 2024 05:57:26 +0000 Message-ID: <20240707055727.3006843-2-e@80x24.org> In-Reply-To: <20240707055727.3006843-1-e@80x24.org> References: <20240707055727.3006843-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While we can't avoid the expensive manifest.js.gz generation, non-Varnish users now get the bandwidth savings from seeing a 304 response. This has no effect on Varnish users since Varnish will forward the request to us without If-Modified-Since if it gets a cache miss, and handle 304 for us on cache hits. --- lib/PublicInbox/ManifestJsGz.pm | 6 +++++- t/www_listing.t | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/ManifestJsGz.pm b/lib/PublicInbox/ManifestJsGz.pm index be5d5f2a..f912f812 100644 --- a/lib/PublicInbox/ManifestJsGz.pm +++ b/lib/PublicInbox/ManifestJsGz.pm @@ -107,8 +107,12 @@ sub psgi_triple { } $manifest = $json->encode($manifest); gzip(\$manifest => \(my $out)); + my $mtime = time2str($ctx->{-mtime}); + if (my $ims = $ctx->{env}->{HTTP_IF_MODIFIED_SINCE}) { + return [ 304, [], [] ] if $mtime eq $ims; + } [ 200, [ qw(Content-Type application/gzip), - 'Last-Modified', time2str($ctx->{-mtime}), + 'Last-Modified', $mtime, 'Content-Length', length($out) ], [ $out ] ] } diff --git a/t/www_listing.t b/t/www_listing.t index 0a4c79e8..5bca4570 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -6,7 +6,7 @@ use v5.12; use PublicInbox::TestCommon; use PublicInbox::Import; use IO::Uncompress::Gunzip qw(gunzip); require_mods(qw(json URI::Escape Plack::Builder HTTP::Tiny)); -require_cmd 'curl'; +my $curl = require_cmd 'curl'; require PublicInbox::WwwListing; require PublicInbox::ManifestJsGz; use PublicInbox::Config; @@ -177,6 +177,15 @@ EOM $td = start_script($cmd, $env, { 3 => $sock }); + my $local_mfest = "$tmpdir/local.manifest.js.gz"; + xsys_e [$curl, '-gsSfR', '-o', $local_mfest, + "http://$host:$port/manifest.js.gz" ]; + xsys_e [$curl, '-vgsSfR', '-o', "$tmpdir/again.js.gz", + '-z', $local_mfest, "http://$host:$port/manifest.js.gz" ], + undef, { 2 => \(my $curl_err) }; + like $curl_err, qr! HTTP/1\.[012] 304 !sm, + 'got 304 response w/ If-Modified-Since'; + # default publicinboxGrokManifest match=domain default tiny_test($json, $host, $port);