Use onThreadCreation to set default SSL context for each thread (#5265)

Fixes: #4998
This commit is contained in:
Ruslan Mustakov 2017-01-24 03:04:14 +07:00 • committed by Andreas Rumpf
commit 35d48765fb
2 changed files with 9 additions and 6 deletions

View file

@ -303,9 +303,12 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
when not defined(ssl):
type SSLContext = ref object
let defaultSSLContext: SSLContext = nil
else:
let defaultSSLContext = newContext(verifyMode = CVerifyNone)
var defaultSSLContext {.threadvar.}: SSLContext
when defined(ssl):
defaultSSLContext = newContext(verifyMode = CVerifyNone)
when compileOption("threads"):
onThreadCreation do ():
defaultSSLContext = newContext(verifyMode = CVerifyNone)
proc newProxy*(url: string, auth = ""): Proxy =
## Constructs a new ``TProxy`` object.

View file

@ -1,5 +1,5 @@
discard """
cmd: "nim c -d:ssl $file"
cmd: "nim c --threads:on -d:ssl $file"
"""
import strutils