8170305: URLConnection doesn't handle HTTP/1.1 1xx (informational) messages

Reviewed-by: dfuchs, michaelm
This commit is contained in:
Jaikiran Pai 2022-09-13 05:08:05 +00:00
parent 9cd3e355d1
commit 8bd79d3efd
2 changed files with 243 additions and 1 deletions

View file

@ -968,7 +968,21 @@ public class HttpClient extends NetworkClient {
code = Integer.parseInt(resp, ind, ind + 3, 10);
} catch (Exception e) {}
if (code == HTTP_CONTINUE && ignoreContinue) {
if (code == 101) {
// We don't support protocol upgrade through the "Upgrade:" request header, so if a
// server still unexpectedly sends a 101 response, we consider that a protocol violation
// and close the connection.
closeServer();
logFinest("Closed connection due to unexpected 101 response");
// clear off the response headers so that they don't get propagated
// to the application
responses.reset();
throw new ProtocolException("Unexpected 101 response from server");
}
// ignore interim informational responses and continue to wait for final response.
if ((code == HTTP_CONTINUE && ignoreContinue)
|| (code >= 102 && code <= 199)) {
logFinest("Ignoring interim informational 1xx response: " + code);
responses.reset();
return parseHTTPHeader(responses, pi, httpuc);
}