From e7f6a68948ebd39c08e0a0a8729aaba1efe2208f Mon Sep 17 00:00:00 2001 From: Bung Date: Tue, 6 Feb 2024 18:17:42 +0800 Subject: [PATCH] fix #109 --- puppy.nimble | 1 + src/puppy/platforms/win32/platform.nim | 8 ++++++-- src/puppy/platforms/win32/windefs.nim | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/puppy.nimble b/puppy.nimble index c19c021..a4f4ce5 100644 --- a/puppy.nimble +++ b/puppy.nimble @@ -9,3 +9,4 @@ requires "nim >= 1.2.2" requires "libcurl >= 1.0.0" requires "zippy >= 0.10.0" requires "webby >= 0.1.6" +requires "winversion" diff --git a/src/puppy/platforms/win32/platform.nim b/src/puppy/platforms/win32/platform.nim index cb8a14a..5d01377 100644 --- a/src/puppy/platforms/win32/platform.nim +++ b/src/puppy/platforms/win32/platform.nim @@ -1,4 +1,5 @@ import puppy/common, std/strutils, utils, windefs, zippy +from winversion import getWindowsVersionEx proc internalFetch*(req: Request): Response {.raises: [PuppyError].} = result = Response() @@ -6,10 +7,13 @@ proc internalFetch*(req: Request): Response {.raises: [PuppyError].} = var hSession, hConnect, hRequest: HINTERNET try: let wideUserAgent = req.headers["user-agent"].wstr() - + {.cast(raises:[]).}: + let infoEx = getWindowsVersionEx() + let lessThan63 = infoEx.dwMajorVersion < 6 or infoEx.dwMajorVersion == 6 and infoEx.dwMinorVersion <= 3 + let dwAccessType = if lessThan63: WINHTTP_ACCESS_TYPE_DEFAULT_PROXY else: WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY hSession = WinHttpOpen( cast[ptr WCHAR](wideUserAgent[0].unsafeAddr), - WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, + dwAccessType.DWORD, nil, nil, 0 diff --git a/src/puppy/platforms/win32/windefs.nim b/src/puppy/platforms/win32/windefs.nim index c265920..9011994 100644 --- a/src/puppy/platforms/win32/windefs.nim +++ b/src/puppy/platforms/win32/windefs.nim @@ -23,6 +23,9 @@ type LPVOID* = pointer const CP_UTF8* = 65001 + WINHTTP_ACCESS_TYPE_NO_PROXY* = 1 + WINHTTP_ACCESS_TYPE_DEFAULT_PROXY* = 2 + WINHTTP_ACCESS_TYPE_NAMED_PROXY* = 3 WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY* = 4 WINHTTP_FLAG_SECURE* = 0x00800000 WINHTTP_ADDREQ_FLAG_ADD* = 0x20000000