From a25c865cb8b9c6c640e80c7a2585c9bae07084f2 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Sat, 23 Jul 2011 18:15:09 +0200 Subject: [PATCH] winhttp: Implement IWinHttpRequest::get_ResponseBody. --- dlls/winhttp/request.c | 27 +++++++++++++++++++++++++-- dlls/winhttp/tests/winhttp.c | 11 ++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index b639f6cc7df..65e0aa76a76 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -2724,8 +2724,31 @@ static HRESULT WINAPI winhttp_request_get_ResponseBody( IWinHttpRequest *iface, VARIANT *body ) { - FIXME("\n"); - return E_NOTIMPL; + struct winhttp_request *request = impl_from_IWinHttpRequest( iface ); + SAFEARRAY *sa; + HRESULT hr; + DWORD err; + char *ptr; + + TRACE("%p, %p\n", request, body); + + if ((err = request_read_body( request, INFINITE ))) return HRESULT_FROM_WIN32( err ); + + if (!(sa = SafeArrayCreateVector( VT_UI1, 0, request->offset ))) return E_OUTOFMEMORY; + if ((hr = SafeArrayAccessData( sa, (void **)&ptr )) != S_OK) + { + SafeArrayDestroy( sa ); + return hr; + } + memcpy( ptr, request->buffer, request->offset ); + if ((hr = SafeArrayUnaccessData( sa )) != S_OK) + { + SafeArrayDestroy( sa ); + return hr; + } + V_VT( body ) = VT_ARRAY|VT_UI1; + V_ARRAY( body ) = sa; + return S_OK; } static HRESULT WINAPI winhttp_request_get_ResponseStream( diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index 8f2af5a5b08..12279021d35 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -2107,7 +2107,7 @@ static void test_IWinHttpRequest(void) HRESULT hr; IWinHttpRequest *req; BSTR method, url, response = NULL, status_text = NULL; - VARIANT async, empty, timeout; + VARIANT async, empty, timeout, body; VARIANT_BOOL succeeded; LONG status; @@ -2241,6 +2241,15 @@ static void test_IWinHttpRequest(void) ok( hr == S_OK, "got %08x\n", hr ); SysFreeString( response ); + VariantInit( &body ); + V_VT( &body ) = VT_ERROR; + hr = IWinHttpRequest_get_ResponseBody( req, &body ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( V_VT( &body ) == (VT_ARRAY|VT_UI1), "got %08x\n", V_VT( &body ) ); + + hr = VariantClear( &body ); + ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_Send( req, empty ); ok( hr == S_OK, "got %08x\n", hr );