diff options
author | Ruslan Mustakov <endragor@users.noreply.github.com> | 2017-01-24 03:04:14 +0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-01-23 21:04:14 +0100 |
commit | 35d48765fb5f5b2f58bf6def54fd744492212097 (patch) | |
tree | 330dc53ff4b4b362c718533169cc097ac72cc10e | |
parent | 268c899b98c5625efc438619805404953ee8e547 (diff) | |
download | Nim-35d48765fb5f5b2f58bf6def54fd744492212097.tar.gz |
Use onThreadCreation to set default SSL context for each thread (#5265)
Fixes: #4998
-rw-r--r-- | lib/pure/httpclient.nim | 13 | ||||
-rw-r--r-- | tests/stdlib/thttpclient.nim | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 760e97049..1ded540ec 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -50,13 +50,13 @@ ## ## echo client.postContent("http://validator.w3.org/check", multipart=data) ## -## You can also make post requests with custom headers. +## You can also make post requests with custom headers. ## This example sets ``Content-Type`` to ``application/json`` ## and uses a json object for the body ## ## .. code-block:: Nim ## import httpclient, json -## +## ## let client = newHttpClient() ## client.headers = newHttpHeaders({ "Content-Type": "application/json" }) ## let body = %*{ @@ -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. diff --git a/tests/stdlib/thttpclient.nim b/tests/stdlib/thttpclient.nim index dd9a6139a..7b1111f9b 100644 --- a/tests/stdlib/thttpclient.nim +++ b/tests/stdlib/thttpclient.nim @@ -1,5 +1,5 @@ discard """ - cmd: "nim c -d:ssl $file" + cmd: "nim c --threads:on -d:ssl $file" """ import strutils |