Use onThreadCreation to set default SSL context for each thread (#5265)
Fixes: #4998
This commit is contained in:
parent
268c899b98
commit
35d48765fb
2 changed files with 9 additions and 6 deletions
|
|
@ -50,13 +50,13 @@
|
||||||
##
|
##
|
||||||
## echo client.postContent("http://validator.w3.org/check", multipart=data)
|
## 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``
|
## This example sets ``Content-Type`` to ``application/json``
|
||||||
## and uses a json object for the body
|
## and uses a json object for the body
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## import httpclient, json
|
## import httpclient, json
|
||||||
##
|
##
|
||||||
## let client = newHttpClient()
|
## let client = newHttpClient()
|
||||||
## client.headers = newHttpHeaders({ "Content-Type": "application/json" })
|
## client.headers = newHttpHeaders({ "Content-Type": "application/json" })
|
||||||
## let body = %*{
|
## let body = %*{
|
||||||
|
|
@ -303,9 +303,12 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
|
||||||
|
|
||||||
when not defined(ssl):
|
when not defined(ssl):
|
||||||
type SSLContext = ref object
|
type SSLContext = ref object
|
||||||
let defaultSSLContext: SSLContext = nil
|
var defaultSSLContext {.threadvar.}: SSLContext
|
||||||
else:
|
when defined(ssl):
|
||||||
let defaultSSLContext = newContext(verifyMode = CVerifyNone)
|
defaultSSLContext = newContext(verifyMode = CVerifyNone)
|
||||||
|
when compileOption("threads"):
|
||||||
|
onThreadCreation do ():
|
||||||
|
defaultSSLContext = newContext(verifyMode = CVerifyNone)
|
||||||
|
|
||||||
proc newProxy*(url: string, auth = ""): Proxy =
|
proc newProxy*(url: string, auth = ""): Proxy =
|
||||||
## Constructs a new ``TProxy`` object.
|
## Constructs a new ``TProxy`` object.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim c -d:ssl $file"
|
cmd: "nim c --threads:on -d:ssl $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue