Commit 114bc2b8 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Implement IWinHttpRequest::SetRequestHeader.

parent 2c8765e7
......@@ -2511,8 +2511,33 @@ static HRESULT WINAPI winhttp_request_SetRequestHeader(
BSTR header,
BSTR value )
{
FIXME("\n");
return E_NOTIMPL;
static const WCHAR fmtW[] = {'%','s',':',' ','%','s','\r','\n',0};
static const WCHAR emptyW[] = {0};
struct winhttp_request *request = impl_from_IWinHttpRequest( iface );
DWORD len;
WCHAR *str;
BOOL ret;
TRACE("%p, %s, %s\n", request, debugstr_w(header), debugstr_w(value));
if (!header) return E_INVALIDARG;
if (request->state < REQUEST_STATE_OPEN)
{
return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN );
}
if (request->state >= REQUEST_STATE_SENT)
{
return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND );
}
len = strlenW( header ) + 4;
if (value) len += strlenW( value );
if (!(str = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
sprintfW( str, fmtW, header, value ? value : emptyW );
ret = WinHttpAddRequestHeaders( request->hrequest, str, len, WINHTTP_ADDREQ_FLAG_REPLACE );
heap_free( str );
if (ret) return S_OK;
return HRESULT_FROM_WIN32( get_last_error() );
}
static DWORD wait_for_completion( struct winhttp_request *request, DWORD timeout )
......
......@@ -2113,13 +2113,19 @@ static void test_IWinHttpRequest(void)
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};
static const WCHAR dateW[] = {'D','a','t','e',0};
HRESULT hr;
IWinHttpRequest *req;
BSTR method, url, username, password, response = NULL, status_text = NULL, headers = NULL;
BSTR connection, value = NULL;
BSTR date, today, connection, value = NULL;
VARIANT async, empty, timeout, body, proxy_server, bypass_list;
VARIANT_BOOL succeeded;
LONG status;
WCHAR todayW[WINHTTP_TIME_FORMAT_BUFSIZE];
SYSTEMTIME st;
GetSystemTime( &st );
WinHttpTimeFromSystemTime( &st, todayW );
CoInitialize( NULL );
hr = CoCreateInstance( &CLSID_WinHttpRequest, NULL, CLSCTX_INPROC_SERVER, &IID_IWinHttpRequest, (void **)&req );
......@@ -2248,6 +2254,17 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_SetRequestHeader( req, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
date = SysAllocString( dateW );
hr = IWinHttpRequest_SetRequestHeader( req, date, NULL );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
today = SysAllocString( todayW );
hr = IWinHttpRequest_SetRequestHeader( req, date, today );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
SysFreeString( method );
method = SysAllocString( method1W );
SysFreeString( url );
......@@ -2312,6 +2329,12 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_SetRequestHeader( req, date, today );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetRequestHeader( req, date, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );
......@@ -2370,6 +2393,9 @@ static void test_IWinHttpRequest(void)
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( value );
hr = IWinHttpRequest_SetRequestHeader( req, date, today );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND ), "got %08x\n", hr );
VariantInit( &timeout );
V_VT( &timeout ) = VT_I4;
V_I4( &timeout ) = 10;
......@@ -2428,6 +2454,9 @@ static void test_IWinHttpRequest(void)
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( value );
hr = IWinHttpRequest_SetRequestHeader( req, date, today );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND ), "got %08x\n", hr );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );
......@@ -2444,6 +2473,8 @@ static void test_IWinHttpRequest(void)
SysFreeString( url );
SysFreeString( username );
SysFreeString( password );
SysFreeString( date );
SysFreeString( today );
VariantClear( &proxy_server );
VariantClear( &bypass_list );
CoUninitialize();
......
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