Commit 9237479d authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Implement IWinHttpRequest::SetProxy.

parent 24eaf193
......@@ -2168,6 +2168,7 @@ struct winhttp_request
LONG connect_timeout;
LONG send_timeout;
LONG receive_timeout;
WINHTTP_PROXY_INFO proxy;
};
static inline struct winhttp_request *impl_from_IWinHttpRequest( IWinHttpRequest *iface )
......@@ -2355,8 +2356,34 @@ static HRESULT WINAPI winhttp_request_SetProxy(
VARIANT proxy_server,
VARIANT bypass_list )
{
FIXME("\n");
return E_NOTIMPL;
struct winhttp_request *request = impl_from_IWinHttpRequest( iface );
TRACE("%p, %u, %s, %s\n", request, proxy_setting, debugstr_variant(&proxy_server),
debugstr_variant(&bypass_list));
switch (proxy_setting)
{
case HTTPREQUEST_PROXYSETTING_DEFAULT:
request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_DEFAULT_PROXY;
request->proxy.lpszProxy = NULL;
request->proxy.lpszProxyBypass = NULL;
break;
case HTTPREQUEST_PROXYSETTING_DIRECT:
request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
request->proxy.lpszProxy = NULL;
request->proxy.lpszProxyBypass = NULL;
break;
case HTTPREQUEST_PROXYSETTING_PROXY:
request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
request->proxy.lpszProxy = V_BSTR( &proxy_server );
request->proxy.lpszProxyBypass = V_BSTR( &bypass_list );
break;
default: return E_INVALIDARG;
}
return S_OK;
}
static HRESULT WINAPI winhttp_request_SetCredentials(
......@@ -2557,6 +2584,10 @@ static HRESULT WINAPI winhttp_request_Send(
}
if (request->state >= REQUEST_STATE_SENT) return ERROR_SUCCESS;
if (!WinHttpSetOption( request->hrequest, WINHTTP_OPTION_PROXY, &request->proxy, sizeof(request->proxy) ))
{
return HRESULT_FROM_WIN32( get_last_error() );
}
if (!WinHttpSetTimeouts( request->hrequest,
request->resolve_timeout,
request->connect_timeout,
......@@ -2855,6 +2886,9 @@ static HRESULT WINAPI winhttp_request_Abort(
request->bytes_available = 0;
request->bytes_read = 0;
request->error = ERROR_SUCCESS;
request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_DEFAULT_PROXY;
request->proxy.lpszProxy = NULL;
request->proxy.lpszProxyBypass = NULL;
return S_OK;
}
......
......@@ -2110,10 +2110,12 @@ static void test_IWinHttpRequest(void)
static const WCHAR url2W[] = {'w','i','n','e','h','q','.','o','r','g',0};
static const WCHAR method1W[] = {'G','E','T',0};
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};
HRESULT hr;
IWinHttpRequest *req;
BSTR method, url, username, password, response = NULL, status_text = NULL;
VARIANT async, empty, timeout, body;
VARIANT async, empty, timeout, body, proxy_server, bypass_list;
VARIANT_BOOL succeeded;
LONG status;
......@@ -2198,6 +2200,19 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_SetCredentials( req, NULL, NULL, 0xdeadbeef );
ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
VariantInit( &proxy_server );
V_VT( &proxy_server ) = VT_ERROR;
VariantInit( &bypass_list );
V_VT( &bypass_list ) = VT_ERROR;
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
SysFreeString( method );
method = SysAllocString( method1W );
SysFreeString( url );
......@@ -2228,6 +2243,19 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
ok( hr == S_OK, "got %08x\n", hr );
V_VT( &proxy_server ) = VT_BSTR;
V_BSTR( &proxy_server ) = SysAllocString( proxy_serverW );
V_VT( &bypass_list ) = VT_BSTR;
V_BSTR( &bypass_list ) = SysAllocString( bypas_listW );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, 0xdeadbeef, proxy_server, bypass_list );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );
......@@ -2247,6 +2275,12 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
VariantInit( &timeout );
V_VT( &timeout ) = VT_I4;
V_I4( &timeout ) = 10;
......@@ -2263,6 +2297,12 @@ static void test_IWinHttpRequest(void)
hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );
......@@ -2279,6 +2319,12 @@ static void test_IWinHttpRequest(void)
hr = VariantClear( &body );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
ok( hr == S_OK, "got %08x\n", hr );
hr = IWinHttpRequest_Send( req, empty );
ok( hr == S_OK, "got %08x\n", hr );
......@@ -2295,6 +2341,8 @@ static void test_IWinHttpRequest(void)
SysFreeString( url );
SysFreeString( username );
SysFreeString( password );
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