Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #109 #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2.0"
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