Commit ee68473f authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

wininet: Reconnect if persistent connection was closed by server.

parent c0091077
......@@ -3454,6 +3454,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *lpwhr, LPCWSTR lpszHeaders,
do
{
DWORD len;
BOOL reusing_connection;
char *ascii_req;
loop_next = FALSE;
......@@ -3504,6 +3505,11 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *lpwhr, LPCWSTR lpszHeaders,
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 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *lpwhr, LPCWSTR lpszHeaders,
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 @@ static INT HTTP_GetResponseHeaders(http_request_t *lpwhr, BOOL clear)
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 @@ static INT HTTP_GetResponseHeaders(http_request_t *lpwhr, BOOL clear)
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? */
......
......@@ -770,6 +770,8 @@ DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int
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 @@ DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int
/* 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment