From 3053b98ab8461691fb61520222495674d96d7811 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 14 Feb 2025 15:45:57 +0100 Subject: [PATCH] WinHTTP: Add http_proxy_info Signed-off-by: Simon Rozman --- include/WinStd/WinHTTP.h | 48 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/include/WinStd/WinHTTP.h b/include/WinStd/WinHTTP.h index bca0c098..b9601600 100644 --- a/include/WinStd/WinHTTP.h +++ b/include/WinStd/WinHTTP.h @@ -20,7 +20,7 @@ /// /// \sa [WinHttpQueryHeaders function](https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpqueryheaders) /// -inline _Success_(return) BOOL WinHttpQueryHeaders(_In_ HINTERNET hRequest, _In_ DWORD dwInfoLevel, _Out_ DWORD& dwData) +inline _Success_(return) BOOL WinHttpQueryHeaders(_In_ HINTERNET hRequest, _In_ DWORD dwInfoLevel, _Out_ DWORD & dwData) { DWORD dwSize = sizeof(dwData); if (WinHttpQueryHeaders(hRequest, dwInfoLevel | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX, &dwData, &dwSize, WINHTTP_NO_HEADER_INDEX)) { @@ -35,7 +35,7 @@ inline _Success_(return) BOOL WinHttpQueryHeaders(_In_ HINTERNET hRequest, _In_ /// /// \sa [WinHttpQueryHeaders function](https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpqueryheaders) /// -inline _Success_(return) BOOL WinHttpQueryHeaders(_In_ HINTERNET hRequest, _In_ DWORD dwInfoLevel, _Inout_ std::wstring& sData) +inline _Success_(return) BOOL WinHttpQueryHeaders(_In_ HINTERNET hRequest, _In_ DWORD dwInfoLevel, _Inout_ std::wstring & sData) { DWORD dwSize = 0x100; for (;;) { @@ -96,5 +96,49 @@ namespace winstd } }; + /// + /// WINHTTP_PROXY_INFO wrapper class + /// + /// \sa [WinHttpGetProxyForUrl function](https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpgetproxyforurl) + /// + struct http_proxy_info : public WINHTTP_PROXY_INFO + { + http_proxy_info() + { + dwAccessType = 0; + lpszProxy = NULL; + lpszProxyBypass = NULL; + } + + http_proxy_info(_Inout_ WINHTTP_PROXY_INFO&& other) + { + dwAccessType = other.dwAccessType; + lpszProxy = other.lpszProxy; + other.lpszProxy = NULL; + lpszProxyBypass = other.lpszProxyBypass; + other.lpszProxyBypass = NULL; + } + + http_proxy_info& operator=(_Inout_ WINHTTP_PROXY_INFO&& other) + { + if (this != std::addressof(other)) { + dwAccessType = other.dwAccessType; + if (lpszProxy) GlobalFree(lpszProxy); + lpszProxy = other.lpszProxy; + other.lpszProxy = NULL; + if (lpszProxyBypass) GlobalFree(lpszProxyBypass); + lpszProxyBypass = other.lpszProxyBypass; + other.lpszProxyBypass = NULL; + } + return *this; + } + + ~http_proxy_info() + { + if (lpszProxy) GlobalFree(lpszProxy); + if (lpszProxyBypass) GlobalFree(lpszProxyBypass); + } + }; + /// @} }