From 4cfc68cda3e3a10abc0b9cf7815dc3acf3547351 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Tue, 3 Nov 2026 13:54:10 +0000 Subject: [PATCH] FetchHTTP2: Default Alt-Svc max age to 24 hours An Alt-Svc header without an ma parameter set the HTTP/3 expiry to the current time, so the alternative was discarded straight away and HTTP/3 was never used for that server. RFC 7838 defines the default freshness lifetime as 24 hours, which the code comment already states. --- .../org/archive/modules/fetcher/FetchHTTP2.java | 4 ++-- .../archive/modules/fetcher/FetchHTTP2Test.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/src/main/java/org/archive/modules/fetcher/FetchHTTP2.java b/modules/src/main/java/org/archive/modules/fetcher/FetchHTTP2.java index e2d32210..f3f9bde7 100644 --- a/modules/src/main/java/org/archive/modules/fetcher/FetchHTTP2.java +++ b/modules/src/main/java/org/archive/modules/fetcher/FetchHTTP2.java @@ -391,7 +391,7 @@ public class FetchHTTP2 extends Processor implements Lifecycle, InitializingBean * Handles the Alt-Svc HTTP header to enable HTTP/3 alternative service. * Does nothing if useHTTP3 is disabled. */ - private void handleAltSvcHeader(CrawlURI curi, Response response) { + void handleAltSvcHeader(CrawlURI curi, Response response) { if (!useHTTP3) return; if (!curi.getUURI().getScheme().equals("https")) return; @@ -449,7 +449,7 @@ public class FetchHTTP2 extends Processor implements Lifecycle, InitializingBean if (port < 1 || port >= 1024) continue; // Calculate the expiry time (default 24 hours) - long maxAgeSeconds = 0; + long maxAgeSeconds = 24 * 60 * 60; String maParameter = parameters.get("ma"); if (maParameter != null) { try { diff --git a/modules/src/test/java/org/archive/modules/fetcher/FetchHTTP2Test.java b/modules/src/test/java/org/archive/modules/fetcher/FetchHTTP2Test.java index 08904706..c040c29b 100644 --- a/modules/src/test/java/org/archive/modules/fetcher/FetchHTTP2Test.java +++ b/modules/src/test/java/org/archive/modules/fetcher/FetchHTTP2Test.java @@ -27,6 +27,8 @@ import org.archive.spring.ConfigPath; import org.archive.util.Recorder; import org.bbottema.javasocksproxyserver.SocksServer; import org.bbottema.javasocksproxyserver.auth.UsernamePasswordAuthenticator; +import org.eclipse.jetty.client.transport.HttpResponse; +import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.proxy.ProxyHandler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -313,4 +315,16 @@ public class FetchHTTP2Test { assertEquals(-2, curi.getFetchStatus()); curi.getRecorder().cleanup(); } + + @Test + public void testAltSvcWithoutMaxAgeDefaultsTo24Hours() throws Exception { + fetcher.start(); + fetcher.setUseHTTP3(true); + var curi = new CrawlURI(UURIFactory.getInstance("https://example.com/")); + var response = new HttpResponse(fetcher.httpClient.newRequest("https://example.com/")); + response.headers(headers -> headers.put(HttpHeader.ALT_SVC, "h3=\":443\"")); + fetcher.handleAltSvcHeader(curi, response); + Thread.sleep(10); // an entry that expires immediately would be gone by now + assertEquals(443, fetcher.serverCache.getServerFor(curi.getUURI()).getHttp3AltSvcPort()); + } }