8291638: Keep-Alive timeout of 0 should close connection immediately
Reviewed-by: dfuchs, jpai
This commit is contained in:
parent
6ae7e4d4aa
commit
26ac836636
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -26,6 +26,7 @@
|
|||||||
package sun.net.www;
|
package sun.net.www;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
/* This is useful for the nightmare of parsing multi-part HTTP/RFC822 headers
|
/* This is useful for the nightmare of parsing multi-part HTTP/RFC822 headers
|
||||||
* sensibly:
|
* sensibly:
|
||||||
@ -246,6 +247,19 @@ public class HeaderParser {
|
|||||||
return Default;
|
return Default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OptionalInt findInt(String k) {
|
||||||
|
try {
|
||||||
|
String s = findValue(k);
|
||||||
|
if (s == null) {
|
||||||
|
return OptionalInt.empty();
|
||||||
|
}
|
||||||
|
return OptionalInt.of(Integer.parseInt(s));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
return OptionalInt.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static void main(String[] a) throws Exception {
|
public static void main(String[] a) throws Exception {
|
||||||
System.out.print("enter line to parse> ");
|
System.out.print("enter line to parse> ");
|
||||||
|
@ -29,6 +29,7 @@ import java.io.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.OptionalInt;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@ -127,6 +128,7 @@ public class HttpClient extends NetworkClient {
|
|||||||
* 0: the server specified no keep alive headers
|
* 0: the server specified no keep alive headers
|
||||||
* -1: the server provided "Connection: keep-alive" but did not specify a
|
* -1: the server provided "Connection: keep-alive" but did not specify a
|
||||||
* a particular time in a "Keep-Alive:" headers
|
* a particular time in a "Keep-Alive:" headers
|
||||||
|
* -2: the server provided "Connection: keep-alive" and timeout=0
|
||||||
* Positive values are the number of seconds specified by the server
|
* Positive values are the number of seconds specified by the server
|
||||||
* in a "Keep-Alive" header
|
* in a "Keep-Alive" header
|
||||||
*/
|
*/
|
||||||
@ -903,11 +905,19 @@ public class HttpClient extends NetworkClient {
|
|||||||
if (keepAliveConnections < 0) {
|
if (keepAliveConnections < 0) {
|
||||||
keepAliveConnections = usingProxy?50:5;
|
keepAliveConnections = usingProxy?50:5;
|
||||||
}
|
}
|
||||||
keepAliveTimeout = p.findInt("timeout", -1);
|
OptionalInt timeout = p.findInt("timeout");
|
||||||
if (keepAliveTimeout < -1) {
|
if (timeout.isEmpty()) {
|
||||||
// if the server specified a negative (invalid) value
|
|
||||||
// then we set to -1, which is equivalent to no value
|
|
||||||
keepAliveTimeout = -1;
|
keepAliveTimeout = -1;
|
||||||
|
} else {
|
||||||
|
keepAliveTimeout = timeout.getAsInt();
|
||||||
|
if (keepAliveTimeout < 0) {
|
||||||
|
// if the server specified a negative (invalid) value
|
||||||
|
// then we set to -1, which is equivalent to no value
|
||||||
|
keepAliveTimeout = -1;
|
||||||
|
} else if (keepAliveTimeout == 0) {
|
||||||
|
// handled specially to mean close connection immediately
|
||||||
|
keepAliveTimeout = -2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (b[7] != '0') {
|
} else if (b[7] != '0') {
|
||||||
|
@ -173,6 +173,8 @@ public class KeepAliveCache
|
|||||||
// different default for server and proxy
|
// different default for server and proxy
|
||||||
keepAliveTimeout = http.getUsingProxy() ? 60 : 5;
|
keepAliveTimeout = http.getUsingProxy() ? 60 : 5;
|
||||||
}
|
}
|
||||||
|
} else if (keepAliveTimeout == -2) {
|
||||||
|
keepAliveTimeout = 0;
|
||||||
}
|
}
|
||||||
// at this point keepAliveTimeout is the number of seconds to keep
|
// at this point keepAliveTimeout is the number of seconds to keep
|
||||||
// alive, which could be 0, if the user specified 0 for the property
|
// alive, which could be 0, if the user specified 0 for the property
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
|
* @bug 8291226 8291638
|
||||||
* @modules java.base/sun.net:+open
|
* @modules java.base/sun.net:+open
|
||||||
* java.base/sun.net.www.http:+open
|
* java.base/sun.net.www.http:+open
|
||||||
* java.base/sun.net.www:+open
|
* java.base/sun.net.www:+open
|
||||||
@ -1015,12 +1016,6 @@ public class KeepAliveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startScenario(int scenarioNumber) throws Exception {
|
private void startScenario(int scenarioNumber) throws Exception {
|
||||||
//test scenarios are skipped because of JDK-8291638
|
|
||||||
if((scenarioNumber >= 112 && scenarioNumber <= 127) || (scenarioNumber >= 144 && scenarioNumber <= 159)) {
|
|
||||||
System.out.println("Scenario Skipped:"+scenarioNumber);
|
|
||||||
this.countDownLatch.countDown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.println("serverScenarios[" + scenarioNumber + "]=" + getServerScenario(scenarioNumber));
|
System.out.println("serverScenarios[" + scenarioNumber + "]=" + getServerScenario(scenarioNumber));
|
||||||
System.out.println("clientScenarios[" + scenarioNumber + "]=" + clientScenarios[getClientScenarioNumber(scenarioNumber)]);
|
System.out.println("clientScenarios[" + scenarioNumber + "]=" + clientScenarios[getClientScenarioNumber(scenarioNumber)]);
|
||||||
if(expectedValues[scenarioNumber] == 0) {
|
if(expectedValues[scenarioNumber] == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user