8314978: Multiple server call from connection failing with expect100 in getOutputStream

Reviewed-by: dfuchs
This commit is contained in:
Vyom Tewari 2023-10-08 05:13:00 +00:00
parent dc4bc4f084
commit 460ebcd9cb
2 changed files with 268 additions and 0 deletions

View file

@ -404,6 +404,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
calls getInputStream after disconnect */
private Exception rememberedException = null;
/* Remembered Exception, we will throw it again if somebody
calls getOutputStream after disconnect or error */
private Exception rememberedExceptionOut = null;
/* If we decide we want to reuse a client, we put it here */
private HttpClient reuseClient = null;
@ -1431,6 +1435,14 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
+ " if doOutput=false - call setDoOutput(true)");
}
if (rememberedExceptionOut != null) {
if (rememberedExceptionOut instanceof RuntimeException) {
throw new RuntimeException(rememberedExceptionOut);
} else {
throw getChainedException((IOException) rememberedExceptionOut);
}
}
if (method.equals("GET")) {
method = "POST"; // Backward compatibility
}
@ -1490,9 +1502,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
int i = responseCode;
disconnectInternal();
responseCode = i;
rememberedExceptionOut = e;
throw e;
} catch (RuntimeException | IOException e) {
disconnectInternal();
rememberedExceptionOut = e;
throw e;
}
}