Skip to content

Commit 50c37f5

Browse files
committed
8276798: HttpURLConnection sends invalid HTTP request
Reviewed-by: dfuchs, michaelm
1 parent 270cf67 commit 50c37f5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,13 @@ private void writeRequests() throws IOException {
626626
* to last and last, respectively, in the case of a POST
627627
* request.
628628
*/
629-
if (!failedOnce) {
629+
final String requestLine = method + " " + getRequestURI()+ " " + httpVersion;
630+
final int requestLineIndex = requests.getKey(requestLine);
631+
if (requestLineIndex != 0) {
632+
// we expect the request line to be at index 0. we set it here
633+
// if we don't find the request line at that index.
630634
checkURLFile();
631-
requests.prepend(method + " " + getRequestURI()+" " +
632-
httpVersion, null);
635+
requests.prepend(requestLine, null);
633636
}
634637
if (!getUseCaches()) {
635638
requests.setIfNotSet ("Cache-Control", "no-cache");
@@ -656,8 +659,7 @@ private void writeRequests() throws IOException {
656659
* or if keep alive is disabled via a system property
657660
*/
658661

659-
// Try keep-alive only on first attempt
660-
if (!failedOnce && http.getHttpKeepAliveSet()) {
662+
if (http.getHttpKeepAliveSet()) {
661663
if (http.usingProxy && tunnelState() != TunnelState.TUNNELING) {
662664
requests.setIfNotSet("Proxy-Connection", "keep-alive");
663665
} else {

0 commit comments

Comments
 (0)