winhttp: Read any data left in the request buffer for websocket connections.

Fixes the case where a websocket server sends an unsolicited frame with the upgrade response.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2021-09-22 12:44:13 +02:00 committed by Alexandre Julliard
parent 54742a9001
commit f738af16fb
1 changed files with 14 additions and 3 deletions

View File

@ -3309,9 +3309,20 @@ DWORD WINAPI WinHttpWebSocketSend( HINTERNET hsocket, WINHTTP_WEB_SOCKET_BUFFER_
static DWORD receive_bytes( struct socket *socket, char *buf, DWORD len, DWORD *ret_len )
{
DWORD err;
if ((err = netconn_recv( socket->request->netconn, buf, len, 0, (int *)ret_len ))) return err;
if (*ret_len != len) return ERROR_WINHTTP_INVALID_SERVER_RESPONSE;
DWORD err, size = 0, needed = len;
char *ptr = buf;
int received;
if (socket->request->read_size)
{
size = min( needed, socket->request->read_size );
memcpy( ptr, socket->request->read_buf + socket->request->read_pos, size );
remove_data( socket->request, size );
needed -= size;
ptr += size;
}
if ((err = netconn_recv( socket->request->netconn, ptr, needed, 0, &received ))) return err;
if ((*ret_len = size + received) != len) return ERROR_WINHTTP_INVALID_SERVER_RESPONSE;
return ERROR_SUCCESS;
}