Hans Leidekker : winhttp: Implement IWinHttpRequest::SetRequestHeader.
Alexandre Julliard
julliard at winehq.org
Tue Jul 26 11:37:56 CDT 2011
Module: wine
Branch: master
Commit: 114bc2b85606db340924b422a17d003d3e1f2ca9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=114bc2b85606db340924b422a17d003d3e1f2ca9
Author: Hans Leidekker <hans at codeweavers.com>
Date: Tue Jul 26 09:27:41 2011 +0200
winhttp: Implement IWinHttpRequest::SetRequestHeader.
---
dlls/winhttp/request.c | 29 +++++++++++++++++++++++++++--
dlls/winhttp/tests/winhttp.c | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 2a2d403..3093bd3 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -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 )
diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c
index 0f932b3..df8dd40 100644
--- a/dlls/winhttp/tests/winhttp.c
+++ b/dlls/winhttp/tests/winhttp.c
@@ -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();
More information about the wine-cvs
mailing list