Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Feb 6, 2024
1 parent 9383298 commit e7f6a68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions puppy.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 6 additions & 2 deletions src/puppy/platforms/win32/platform.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import puppy/common, std/strutils, utils, windefs, zippy
from winversion import getWindowsVersionEx

proc internalFetch*(req: Request): Response {.raises: [PuppyError].} =
result = Response()

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
Expand Down
3 changes: 3 additions & 0 deletions src/puppy/platforms/win32/windefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7f6a68

Please sign in to comment.