mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-22 21:57:17 +00:00
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.
This commit is contained in:
2 files changed
+16
-2
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user