wininet: Reconnect if persistent connection was closed by server.
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 200d03f..4b4bc5b 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -3454,6 +3454,7 @@
do
{
DWORD len;
+ BOOL reusing_connection;
char *ascii_req;
loop_next = FALSE;
@@ -3504,6 +3505,11 @@
TRACE("Request header -> %s\n", debugstr_w(requestString) );
/* Send the request and store the results */
+ if(NETCON_connected(&lpwhr->netConnection))
+ reusing_connection = TRUE;
+ else
+ reusing_connection = FALSE;
+
if ((res = HTTP_OpenConnection(lpwhr)) != ERROR_SUCCESS)
goto lend;
@@ -3545,6 +3551,13 @@
goto lend;
responseLen = HTTP_GetResponseHeaders(lpwhr, TRUE);
+ /* FIXME: We should know that connection is closed before sending
+ * headers. Otherwise wrong callbacks are executed */
+ if(!responseLen && reusing_connection) {
+ TRACE("Connection closed by server, reconnecting\n");
+ loop_next = TRUE;
+ continue;
+ }
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen,
@@ -4457,9 +4470,6 @@
TRACE("-->\n");
- /* clear old response headers (eg. from a redirect response) */
- if (clear) HTTP_clear_response_headers( lpwhr );
-
if (!NETCON_connected(&lpwhr->netConnection))
goto lend;
@@ -4471,6 +4481,13 @@
buflen = MAX_REPLY_LEN;
if (!read_line(lpwhr, bufferA, &buflen))
goto lend;
+
+ /* clear old response headers (eg. from a redirect response) */
+ if (clear) {
+ HTTP_clear_response_headers( lpwhr );
+ clear = FALSE;
+ }
+
rc += buflen;
MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
/* check is this a status code line? */
diff --git a/dlls/wininet/netconnection.c b/dlls/wininet/netconnection.c
index 5aa647a..abd7415 100644
--- a/dlls/wininet/netconnection.c
+++ b/dlls/wininet/netconnection.c
@@ -770,6 +770,8 @@
if (!connection->useSSL)
{
*recvd = recv(connection->socketFD, buf, len, flags);
+ if(!*recvd)
+ NETCON_close(connection);
return *recvd == -1 ? sock_get_error(errno) : ERROR_SUCCESS;
}
else
@@ -779,8 +781,10 @@
/* Check if EOF was received */
if(!*recvd && (pSSL_get_error(connection->ssl_s, *recvd)==SSL_ERROR_ZERO_RETURN
- || pSSL_get_error(connection->ssl_s, *recvd)==SSL_ERROR_SYSCALL))
+ || pSSL_get_error(connection->ssl_s, *recvd)==SSL_ERROR_SYSCALL)) {
+ NETCON_close(connection);
return ERROR_SUCCESS;
+ }
return *recvd > 0 ? ERROR_SUCCESS : ERROR_INTERNET_CONNECTION_ABORTED;
#else