| Index: src/DefaultWebRequestWinInet.cpp |
| =================================================================== |
| --- a/src/DefaultWebRequestWinInet.cpp |
| +++ b/src/DefaultWebRequestWinInet.cpp |
| @@ -19,7 +19,7 @@ |
| #include <algorithm> |
| #include <sstream> |
| #include <Windows.h> |
| -#include <winhttp.h> |
| +#include <WinInet.h> |
| #include <Shlwapi.h> |
| #include "Utils.h" |
| @@ -32,7 +32,7 @@ |
| ~WinHttpHandle() |
| { |
| - if (handle) WinHttpCloseHandle(handle); |
| + if (handle) InternetCloseHandle(handle); |
| handle = 0; |
| } |
| // Overloaded HINTERNET cast |
| @@ -50,15 +50,15 @@ |
| return AdblockPlus::WebRequest::NS_ERROR_NOT_INITIALIZED; |
| case ERROR_OUTOFMEMORY: |
| return AdblockPlus::WebRequest::NS_ERROR_OUT_OF_MEMORY; |
| - case ERROR_WINHTTP_UNRECOGNIZED_SCHEME: |
| + case ERROR_INTERNET_UNRECOGNIZED_SCHEME: |
| return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_PROTOCOL; |
| - case ERROR_WINHTTP_CONNECTION_ERROR: |
| + case ERROR_INTERNET_CANNOT_CONNECT: |
| return AdblockPlus::WebRequest::NS_ERROR_NET_INTERRUPT; |
| - case ERROR_WINHTTP_INVALID_URL: |
| + case ERROR_INTERNET_INVALID_URL: |
| return AdblockPlus::WebRequest::NS_ERROR_MALFORMED_URI; |
| - case ERROR_WINHTTP_TIMEOUT: |
| + case ERROR_INTERNET_TIMEOUT: |
| return AdblockPlus::WebRequest::NS_ERROR_NET_TIMEOUT; |
| - case ERROR_WINHTTP_NAME_NOT_RESOLVED: |
| + case ERROR_INTERNET_NAME_NOT_RESOLVED: |
| return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_HOST; |
| default: |
| @@ -66,48 +66,6 @@ |
| } |
| } |
| -BOOL GetProxySettings(std::wstring& proxyName, std::wstring& proxyBypass) |
| -{ |
| - BOOL bResult = TRUE; |
| - |
| - // Get Proxy config info. |
| - WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig; |
| - |
| - ::ZeroMemory(&proxyConfig, sizeof(proxyConfig)); |
| - |
| - if (WinHttpGetIEProxyConfigForCurrentUser(&proxyConfig)) |
| - { |
| - if (proxyConfig.lpszProxy != 0) |
| - { |
| - proxyName.assign(proxyConfig.lpszProxy); |
| - } |
| - if (proxyConfig.lpszProxyBypass != 0) |
| - { |
| - proxyBypass.assign(proxyConfig.lpszProxyBypass); |
| - } |
| - } |
| - else |
| - { |
| - bResult = FALSE; |
| - } |
| - |
| - // The strings need to be freed. |
| - if (proxyConfig.lpszProxy != NULL) |
| - { |
| - ::GlobalFree(proxyConfig.lpszProxy); |
| - } |
| - if (proxyConfig.lpszAutoConfigUrl != NULL) |
| - { |
| - ::GlobalFree(proxyConfig.lpszAutoConfigUrl); |
| - } |
| - if (proxyConfig.lpszProxyBypass!= NULL) |
| - { |
| - ::GlobalFree(proxyConfig.lpszProxyBypass); |
| - } |
| - |
| - return bResult; |
| -} |
| - |
| void ParseResponseHeaders(HINTERNET hRequest, AdblockPlus::ServerResponse* result) |
| { |
| if (!result) |
| @@ -123,7 +81,7 @@ |
| // Parse the response headers |
| BOOL res = 0; |
| DWORD bufLen = 0; |
| - res = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_RAW_HEADERS, WINHTTP_HEADER_NAME_BY_INDEX, WINHTTP_NO_OUTPUT_BUFFER, &bufLen, WINHTTP_NO_HEADER_INDEX); |
| + res = InternetQueryOption(hRequest, HTTP_QUERY_RAW_HEADERS, 0, &bufLen); |
| if (bufLen == 0) |
| { |
| // There are not headers |
| @@ -131,7 +89,7 @@ |
| } |
| std::wstring responseHeaders; |
| responseHeaders.resize(bufLen / sizeof(std::wstring::value_type) + 1); |
| - res = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_RAW_HEADERS, WINHTTP_HEADER_NAME_BY_INDEX, &responseHeaders[0], &bufLen, WINHTTP_NO_HEADER_INDEX); |
| + res = InternetQueryOption(hRequest, HTTP_QUERY_RAW_HEADERS, &responseHeaders[0], &bufLen); |
| if (res) |
| { |
| // Iterate through each header. Separator is '\0' |
| @@ -172,13 +130,13 @@ |
| // Get the response status code |
| std::wstring statusStr; |
| DWORD statusLen = 0; |
| - res = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE, WINHTTP_HEADER_NAME_BY_INDEX, &statusStr[0], &statusLen, WINHTTP_NO_HEADER_INDEX); |
| + res = HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE, &statusStr[0], &statusLen, 0); |
| if (statusLen == 0) |
| { |
| throw std::exception("Can't parse the status code"); |
| } |
| statusStr.resize(statusLen / sizeof(std::wstring::value_type) + 1); |
| - res = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE, WINHTTP_HEADER_NAME_BY_INDEX, &statusStr[0], &statusLen, WINHTTP_NO_HEADER_INDEX); |
| + res = HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE, &statusStr[0], &statusLen, 0); |
| if ((statusLen == 0) || (!res)) |
| { |
| throw std::exception("Can't parse the status code"); |
| @@ -213,23 +171,8 @@ |
| // Use WinHttpOpen to obtain a session handle. |
| std::wstring proxyName, proxyBypass; |
| - GetProxySettings(proxyName, proxyBypass); |
| - if (proxyName.empty()) |
| - { |
| - hSession.handle = WinHttpOpen(L"Adblock Plus", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); |
| - } |
| - else |
| - { |
| - hSession.handle = WinHttpOpen(L"Adblock Plus", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, proxyName.c_str(), proxyBypass.c_str(), 0); |
| + hSession.handle = InternetOpen(L"Adblock Plus", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0); |
| - |
| - // Make sure the proxy is set. Just providing it to the above call is not enough sometimes |
| - WINHTTP_PROXY_INFO proxyInfo; |
| - proxyInfo.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY; |
| - proxyInfo.lpszProxy = (LPWSTR)proxyName.c_str(); |
| - proxyInfo.lpszProxyBypass = (LPWSTR)proxyBypass.c_str(); |
| - WinHttpSetOption(hSession.handle, WINHTTP_OPTION_PROXY , &proxyInfo, sizeof(WINHTTP_PROXY_INFO)); |
| - } |
| if (!hSession) |
| { |
| result.status = WindowsErrorToGeckoError(GetLastError()); |
| @@ -246,7 +189,7 @@ |
| urlComponents.dwHostNameLength = (DWORD)-1; |
| urlComponents.dwUrlPathLength = (DWORD)-1; |
| urlComponents.dwExtraInfoLength = (DWORD)-1; |
| - res = WinHttpCrackUrl(canonizedUrl.c_str(), canonizedUrl.length(), 0, &urlComponents); |
| + res = InternetCrackUrl(canonizedUrl.c_str(), canonizedUrl.length(), 0, &urlComponents); |
| if (!res) |
| { |
| result.status = WindowsErrorToGeckoError(GetLastError()); |
| @@ -254,17 +197,15 @@ |
| } |
| std::wstring hostName(urlComponents.lpszHostName, urlComponents.dwHostNameLength); |
| bool isSecure = urlComponents.nScheme == INTERNET_SCHEME_HTTPS; |
| + // Create an HTTP request handle. |
| if (isSecure) |
| { |
| - hConnect.handle = WinHttpConnect(hSession, hostName.c_str(), urlComponents.nPort, 0); |
| + hConnect.handle = InternetConnect(hSession, hostName.c_str(), urlComponents.nPort, 0, 0, INTERNET_SERVICE_HTTP, 0, 0); |
| } |
| else |
| { |
| - hConnect.handle = WinHttpConnect(hSession, hostName.c_str(), urlComponents.nPort, 0); |
| + hConnect.handle = InternetConnect(hSession, hostName.c_str(), urlComponents.nPort, 0, 0, INTERNET_SERVICE_HTTP, 0, 0); |
| } |
|
Wladimir Palant
2013/10/08 07:24:28
Am I missing something or is this if block complet
|
| - |
| - |
| - // Create an HTTP request handle. |
| if (!hConnect) |
| { |
| result.status = WindowsErrorToGeckoError(GetLastError()); |
| @@ -273,9 +214,9 @@ |
| DWORD flags = 0; |
| if (isSecure) |
| { |
| - flags = WINHTTP_FLAG_SECURE; |
| + flags = INTERNET_FLAG_SECURE; |
| } |
| - hRequest.handle = WinHttpOpenRequest(hConnect, L"GET", urlComponents.lpszUrlPath, 0, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, flags); |
| + hRequest.handle = HttpOpenRequest(hConnect, L"GET", urlComponents.lpszUrlPath, L"HTTP/1.1", 0, 0, flags, 0); |
| // Send a request. |
| if (!hRequest) |
| @@ -283,14 +224,19 @@ |
| result.status = WindowsErrorToGeckoError(GetLastError()); |
| return result; |
| } |
| - // TODO: Make sure for HTTP 1.1 "Accept-Encoding: gzip, deflate" doesn't HAVE to be set here |
| + BOOL b = TRUE; |
| + res = InternetSetOption(hRequest, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b)); |
|
Oleksandr
2013/10/07 21:36:18
This is a key change. Since WinHTTP does not suppo
|
| + if (res == TRUE) |
| + { |
| + headers += L"Accept-Encoding: gzip, deflate\r\n"; |
| + } |
| if (headers.length() > 0) |
| { |
| - res = ::WinHttpSendRequest(hRequest, headers.c_str(), headers.length(), WINHTTP_NO_REQUEST_DATA, 0, 0, 0); |
| + res = ::HttpSendRequest(hRequest, headers.c_str(), headers.length(), 0, 0); |
| } |
| else |
| { |
| - res = ::WinHttpSendRequest(hRequest, 0, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0); |
| + res = ::HttpSendRequest(hRequest, 0, 0, 0, 0); |
| } |
| // End the request. |
| @@ -300,13 +246,6 @@ |
| return result; |
| } |
| - res = WinHttpReceiveResponse(hRequest, 0); |
| - if (!res) |
| - { |
| - result.status = WindowsErrorToGeckoError(GetLastError()); |
| - return result; |
| - } |
| - |
| ParseResponseHeaders(hRequest, &result); |
| std::auto_ptr<char> outBuffer; |
| @@ -318,7 +257,7 @@ |
| { |
| // Check for available data. |
| downloadSize = 0; |
| - if (!WinHttpQueryDataAvailable(hRequest, &downloadSize)) |
| + if (!InternetQueryDataAvailable(hRequest, &downloadSize, 0, 0)) |
| { |
| result.responseStatus = WindowsErrorToGeckoError(GetLastError()); |
| break; |
| @@ -336,7 +275,7 @@ |
| // Read the data. |
| ZeroMemory(outBuffer.get(), downloadSize+1); |
| - if (WinHttpReadData(hRequest, outBuffer.get(), downloadSize, &downloaded)) |
| + if (InternetReadFile(hRequest, outBuffer.get(), downloadSize, &downloaded)) |
| { |
| result.responseText.append(outBuffer.get(), downloaded); |
| } |