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

little things #86

Merged
merged 3 commits into from
Dec 8, 2022
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="docs/puppyBanner.png">

# Puppy - Fetch url resources via HTTP and HTTPS.
# Puppy - Fetch resources via HTTP and HTTPS.

`nimble install puppy`

Expand Down
2 changes: 1 addition & 1 deletion puppy.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = "1.6.0"
author = "Andre von Houck"
description = "Puppy fetches HTML pages for Nim."
description = "Puppy fetches resources via HTTP and HTTPS."
license = "MIT"

srcDir = "src"
Expand Down
4 changes: 2 additions & 2 deletions src/puppy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ else:
export common, urlly

proc addDefaultHeaders(req: Request) =
if req.headers["user-agent"].len == 0:
if req.headers["user-agent"] == "":
req.headers["user-agent"] = "Puppy"
if req.headers["accept-encoding"].len == 0:
if req.headers["accept-encoding"] == "":
# If there isn't a specific accept-encoding specified, enable gzip
req.headers["accept-encoding"] = "gzip"

Expand Down
1 change: 1 addition & 0 deletions src/puppy/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type
verb*: string
body*: string
when defined(puppyLibcurl) or (defined(windows) or not defined(macosx)):
# If you want to use this on Mac, please us -d:puppyLibcurl
allowAnyHttpsCertificate*: bool

Response* = ref object
Expand Down
2 changes: 1 addition & 1 deletion src/puppy/platforms/linux/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ proc fetch*(req: Request): Response {.raises: [PuppyError].} =
discard curl.easy_setopt(OPT_HEADERDATA, headerWrap.addr)
discard curl.easy_setopt(OPT_HEADERFUNCTION, curlWriteFn)

# On windows look for cacert.pem.
# On Windows look for cacert.pem.
when defined(windows):
discard curl.easy_setopt(OPT_CAINFO, "cacert.pem".cstring)
# Follow redirects by default.
Expand Down
1 change: 1 addition & 0 deletions src/puppy/platforms/macos/macdefs.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import objc

export objc

{.passL: "-framework AppKit".}
Expand Down
2 changes: 1 addition & 1 deletion src/puppy/platforms/macos/objc.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import macros, typetraits, strutils
import macros, strutils, typetraits

type
Class* = distinct int
Expand Down
13 changes: 11 additions & 2 deletions src/puppy/platforms/win32/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,17 @@ proc fetch*(req: Request): Response {.raises: [PuppyError].} =
) == 0:

let error = GetLastError()
if error in {ERROR_WINHTTP_SECURE_FAILURE, ERROR_INTERNET_INVALID_CA, ERROR_INTERNET_SEC_CERT_DATE_INVALID, ERROR_INTERNET_SEC_INVALID_CERT, ERROR_INTERNET_SEC_CERT_CN_INVALID, ERROR_INTERNET_SEC_CERT_NO_REV, ERROR_INTERNET_SEC_CERT_REV_FAILED, ERROR_INTERNET_SEC_CERT_REVOKED, ERROR_INTERNET_SEC_CERT_ERRORS} and
req.allowAnyHttpsCertificate:
if error in {
ERROR_WINHTTP_SECURE_FAILURE,
ERROR_INTERNET_INVALID_CA,
ERROR_INTERNET_SEC_CERT_DATE_INVALID,
ERROR_INTERNET_SEC_INVALID_CERT,
ERROR_INTERNET_SEC_CERT_CN_INVALID,
ERROR_INTERNET_SEC_CERT_NO_REV,
ERROR_INTERNET_SEC_CERT_REV_FAILED,
ERROR_INTERNET_SEC_CERT_REVOKED,
ERROR_INTERNET_SEC_CERT_ERRORS
} and req.allowAnyHttpsCertificate:
# If this is a certificate error but we should allow any HTTPS cert,
# we need to set some options and retry sending the request.
# https://stackoverflow.com/questions/19338395/how-do-you-use-winhttp-to-do-ssl-with-a-self-signed-cert
Expand Down
4 changes: 2 additions & 2 deletions src/puppy/platforms/win32/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ proc wstr*(str: string): string =
0,
str.cstring,
str.len.int32,
cast[ptr WCHAR](result[0].addr),
cast[ptr WCHAR](result.cstring),
wlen
)

Expand All @@ -37,7 +37,7 @@ proc `$`*(p: ptr WCHAR): string =
0,
p,
-1,
result[0].addr,
result.cstring,
len,
nil,
nil
Expand Down