winhttp: Implement IWinHttpRequest::GetResponseHeader.

This commit is contained in:
Hans Leidekker 2011-07-26 09:27:23 +02:00 committed by Alexandre Julliard
parent 3638908039
commit 2c8765e7fb
2 changed files with 60 additions and 9 deletions

View File

@ -2515,15 +2515,6 @@ static HRESULT WINAPI winhttp_request_SetRequestHeader(
return E_NOTIMPL;
}
static HRESULT WINAPI winhttp_request_GetResponseHeader(
IWinHttpRequest *iface,
BSTR header,
BSTR *value )
{
FIXME("\n");
return E_NOTIMPL;
}
static DWORD wait_for_completion( struct winhttp_request *request, DWORD timeout )
{
HANDLE handles[2];
@ -2591,6 +2582,37 @@ static DWORD request_wait_for_response( struct winhttp_request *request, DWORD t
return wait_for_completion( request, timeout );
}
static HRESULT WINAPI winhttp_request_GetResponseHeader(
IWinHttpRequest *iface,
BSTR header,
BSTR *value )
{
struct winhttp_request *request = impl_from_IWinHttpRequest( iface );
DWORD err, size;
TRACE("%p, %p\n", request, header);
if (request->state < REQUEST_STATE_SENT)
{
return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND );
}
if (!header || !value) return E_INVALIDARG;
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_CUSTOM, header, NULL, &size, NULL );
err = get_last_error();
if (err != ERROR_INSUFFICIENT_BUFFER) return HRESULT_FROM_WIN32( err );
if (!(*value = SysAllocStringLen( NULL, size / sizeof(WCHAR) ))) return E_OUTOFMEMORY;
if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_CUSTOM, header, *value, &size, NULL ))
{
SysFreeString( *value );
return HRESULT_FROM_WIN32( get_last_error() );
}
return S_OK;
}
static HRESULT WINAPI winhttp_request_GetAllResponseHeaders(
IWinHttpRequest *iface,
BSTR *headers )

View File

@ -2112,9 +2112,11 @@ static void test_IWinHttpRequest(void)
static const WCHAR method2W[] = {'I','N','V','A','L','I','D',0};
static const WCHAR proxy_serverW[] = {'p','r','o','x','y','s','e','r','v','e','r',0};
static const WCHAR bypas_listW[] = {'b','y','p','a','s','s','l','i','s','t',0};
static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n',0};
HRESULT hr;
IWinHttpRequest *req;
BSTR method, url, username, password, response = NULL, status_text = NULL, headers = NULL;
BSTR connection, value = NULL;
VARIANT async, empty, timeout, body, proxy_server, bypass_list;
VARIANT_BOOL succeeded;
LONG status;
@ -2236,6 +2238,16 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_GetResponseHeader( req, NULL, NULL );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
connection = SysAllocString( connectionW );
hr = IWinHttpRequest_GetResponseHeader( req, connection, NULL );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
SysFreeString( method );
method = SysAllocString( method1W );
SysFreeString( url );
@ -2297,6 +2309,9 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );
@ -2345,6 +2360,16 @@ static void test_IWinHttpRequest(void)
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( headers );
hr = IWinHttpRequest_GetResponseHeader( req, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = IWinHttpRequest_GetResponseHeader( req, connection, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( value );
VariantInit( &timeout );
V_VT( &timeout ) = VT_I4;
V_I4( &timeout ) = 10;
@ -2399,6 +2424,10 @@ static void test_IWinHttpRequest(void)
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( headers );
hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( value );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );