| 
1 | 1 | #include <Python.h>  | 
2 | 2 | #include <windows.h>  | 
3 | 3 | #include <bits.h>  | 
 | 4 | +#include <winhttp.h>  | 
4 | 5 | #include <typeinfo>  | 
5 | 6 | 
 
  | 
6 | 7 | #include "helpers.h"  | 
@@ -204,6 +205,30 @@ PyObject *bits_serialize_job(PyObject *, PyObject *args, PyObject *kwargs) {  | 
204 | 205 | }  | 
205 | 206 | 
 
  | 
206 | 207 | 
 
  | 
 | 208 | +static HRESULT _job_setproxy(IBackgroundCopyJob *job) {  | 
 | 209 | +    WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxy_config = { 0 };  | 
 | 210 | +    if (WinHttpGetIEProxyConfigForCurrentUser(&proxy_config)) {  | 
 | 211 | +        if (proxy_config.lpszProxy || proxy_config.lpszAutoConfigUrl || proxy_config.fAutoDetect) {  | 
 | 212 | +            // Global settings are present, and so BITS's default behaviour  | 
 | 213 | +            // should be fine.  | 
 | 214 | +            if (proxy_config.lpszProxy) {  | 
 | 215 | +                GlobalFree(proxy_config.lpszProxy);  | 
 | 216 | +            }  | 
 | 217 | +            if (proxy_config.lpszProxyBypass) {  | 
 | 218 | +                GlobalFree(proxy_config.lpszProxyBypass);  | 
 | 219 | +            }  | 
 | 220 | +            if (proxy_config.lpszAutoConfigUrl) {  | 
 | 221 | +                GlobalFree(proxy_config.lpszAutoConfigUrl);  | 
 | 222 | +            }  | 
 | 223 | +            return S_OK;  | 
 | 224 | +        }  | 
 | 225 | +    }  | 
 | 226 | + | 
 | 227 | +    // Probably no static settings, so tell BITS to do autodetection.  | 
 | 228 | +    return job->SetProxySettings(BG_JOB_PROXY_USAGE_AUTODETECT, NULL, NULL);  | 
 | 229 | +}  | 
 | 230 | + | 
 | 231 | + | 
207 | 232 | static HRESULT _job_setcredentials(IBackgroundCopyJob *job, wchar_t *username, wchar_t *password) {  | 
208 | 233 |     IBackgroundCopyJob2 *job2 = NULL;  | 
209 | 234 |     HRESULT hr;  | 
@@ -256,6 +281,10 @@ PyObject *bits_begin(PyObject *, PyObject *args, PyObject *kwargs) {  | 
256 | 281 |         error_from_bits_hr(bcm, hr, "Creating download job");  | 
257 | 282 |         goto done;  | 
258 | 283 |     }  | 
 | 284 | +    if (FAILED(hr = _job_setproxy(job))) {  | 
 | 285 | +        error_from_bits_hr(bcm, hr, "Setting proxy");  | 
 | 286 | +        goto done;  | 
 | 287 | +    }  | 
259 | 288 |     if ((username || password) && FAILED(hr = _job_setcredentials(job, username, password))) {  | 
260 | 289 |         error_from_bits_hr(bcm, hr, "Adding basic credentials to download job");  | 
261 | 290 |         goto done;  | 
 | 
0 commit comments