|
28 | 28 | import java.io.*; |
29 | 29 | import java.net.*; |
30 | 30 | import java.util.Locale; |
| 31 | +import java.util.OptionalInt; |
31 | 32 | import sun.net.NetworkClient; |
32 | 33 | import sun.net.ProgressSource; |
33 | 34 | import sun.net.www.MessageHeader; |
@@ -119,6 +120,7 @@ static private int getDefaultPort(String proto) { |
119 | 120 | * 0: the server specified no keep alive headers |
120 | 121 | * -1: the server provided "Connection: keep-alive" but did not specify a |
121 | 122 | * a particular time in a "Keep-Alive:" headers |
| 123 | + * -2: the server provided "Connection: keep-alive" and timeout=0 |
122 | 124 | * Positive values are the number of seconds specified by the server |
123 | 125 | * in a "Keep-Alive" header |
124 | 126 | */ |
@@ -819,11 +821,19 @@ private boolean parseHTTPHeader(MessageHeader responses, ProgressSource pi, Http |
819 | 821 | if (keepAliveConnections < 0) { |
820 | 822 | keepAliveConnections = usingProxy?50:5; |
821 | 823 | } |
822 | | - keepAliveTimeout = p.findInt("timeout", -1); |
823 | | - if (keepAliveTimeout < -1) { |
824 | | - // if the server specified a negative (invalid) value |
825 | | - // then we set to -1, which is equivalent to no value |
| 824 | + OptionalInt timeout = p.findInt("timeout"); |
| 825 | + if (!timeout.isPresent()) { |
826 | 826 | keepAliveTimeout = -1; |
| 827 | + } else { |
| 828 | + keepAliveTimeout = timeout.getAsInt(); |
| 829 | + if (keepAliveTimeout < 0) { |
| 830 | + // if the server specified a negative (invalid) value |
| 831 | + // then we set to -1, which is equivalent to no value |
| 832 | + keepAliveTimeout = -1; |
| 833 | + } else if (keepAliveTimeout == 0) { |
| 834 | + // handled specially to mean close connection immediately |
| 835 | + keepAliveTimeout = -2; |
| 836 | + } |
827 | 837 | } |
828 | 838 | } |
829 | 839 | } else if (b[7] != '0') { |
|
0 commit comments