mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-22 13:47:02 +00:00
Merge pull request #803 from RaphaelFakhri/fix-alt-svc-default-max-age
FetchHTTP2: Default Alt-Svc max age to 24 hours
This commit is contained in:
3 files changed
+26
-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 {
|
||||
|
||||
@@ -284,6 +284,14 @@ public class CrawlServer implements Serializable, FetchStats.HasFetchStats, Iden
|
||||
return http3Port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return time in milliseconds since epoch to stop using the HTTP/3
|
||||
* alt-svc port, or 0 if none is set.
|
||||
*/
|
||||
public synchronized long getHttp3AltSvcExpiry() {
|
||||
return http3Expiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key to use doing lookup on server instances.
|
||||
*
|
||||
|
||||
@@ -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,18 @@ 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\""));
|
||||
long before = System.currentTimeMillis();
|
||||
fetcher.handleAltSvcHeader(curi, response);
|
||||
var crawlServer = fetcher.serverCache.getServerFor(curi.getUURI());
|
||||
assertEquals(443, crawlServer.getHttp3AltSvcPort());
|
||||
assertTrue(crawlServer.getHttp3AltSvcExpiry() >= before + 24 * 60 * 60 * 1000L);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user