From ca9ab005fc1aab828fa4630c734e72bbcee5447b Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Tue, 26 Jul 2011 09:26:48 +0200 Subject: [PATCH] winhttp: Implement IWinHttpRequest::GetAllResponseHeaders. --- dlls/winhttp/request.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index 3ae8dbca1a..38150ecce1 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -2524,14 +2524,6 @@ static HRESULT WINAPI winhttp_request_GetResponseHeader( return E_NOTIMPL; } -static HRESULT WINAPI winhttp_request_GetAllResponseHeaders( - IWinHttpRequest *iface, - BSTR *headers ) -{ - FIXME("\n"); - return E_NOTIMPL; -} - static DWORD wait_for_completion( struct winhttp_request *request, DWORD timeout ) { HANDLE handles[2]; @@ -2587,6 +2579,48 @@ static void wait_set_status_callback( struct winhttp_request *request, DWORD sta WinHttpSetStatusCallback( request->hrequest, wait_status_callback, status, 0 ); } +static DWORD request_wait_for_response( struct winhttp_request *request, DWORD timeout ) +{ + if (request->state >= REQUEST_STATE_RESPONSE_RECEIVED) return ERROR_SUCCESS; + + wait_set_status_callback( request, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE ); + if (!WinHttpReceiveResponse( request->hrequest, NULL )) + { + return get_last_error(); + } + return wait_for_completion( request, timeout ); +} + +static HRESULT WINAPI winhttp_request_GetAllResponseHeaders( + IWinHttpRequest *iface, + BSTR *headers ) +{ + struct winhttp_request *request = impl_from_IWinHttpRequest( iface ); + DWORD err, size; + + TRACE("%p, %p\n", request, headers); + + if (!headers) return E_INVALIDARG; + if (request->state < REQUEST_STATE_SENT) + { + return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ); + } + if ((err = request_wait_for_response( request, INFINITE ))) return HRESULT_FROM_WIN32( err ); + request->state = REQUEST_STATE_RESPONSE_RECEIVED; + + size = 0; + WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, NULL, &size, NULL ); + err = get_last_error(); + if (err != ERROR_INSUFFICIENT_BUFFER) return HRESULT_FROM_WIN32( err ); + if (!(*headers = SysAllocStringLen( NULL, size / sizeof(WCHAR) ))) return E_OUTOFMEMORY; + if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, *headers, &size, NULL )) + { + SysFreeString( *headers ); + return HRESULT_FROM_WIN32( get_last_error() ); + } + return S_OK; +} + static HRESULT WINAPI winhttp_request_Send( IWinHttpRequest *iface, VARIANT body ) @@ -2624,18 +2658,6 @@ static HRESULT WINAPI winhttp_request_Send( return S_OK; } -static DWORD request_wait_for_response( struct winhttp_request *request, DWORD timeout ) -{ - if (request->state >= REQUEST_STATE_RESPONSE_RECEIVED) return ERROR_SUCCESS; - - wait_set_status_callback( request, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE ); - if (!WinHttpReceiveResponse( request->hrequest, NULL )) - { - return get_last_error(); - } - return wait_for_completion( request, timeout ); -} - static HRESULT WINAPI winhttp_request_get_Status( IWinHttpRequest *iface, LONG *status )