Handle hostname option properly (#92)
This commit is contained in:
parent
f354dfebe9
commit
e199aa57da
|
@ -168,10 +168,15 @@ proc connect*(
|
|||
version = HttpVersion11,
|
||||
tlsFlags: set[TLSFlags] = {},
|
||||
tlsMinVersion = TLSVersion.TLS11,
|
||||
tlsMaxVersion = TLSVersion.TLS12): Future[T]
|
||||
tlsMaxVersion = TLSVersion.TLS12,
|
||||
hostName = ""): Future[T]
|
||||
{.async, raises: [Defect, HttpError].} =
|
||||
|
||||
let hostPort = host.split(":")
|
||||
let wantedHostName = if hostName.len > 0:
|
||||
hostName
|
||||
else:
|
||||
host.split(":")[0]
|
||||
|
||||
let addrs = resolveTAddress(host)
|
||||
for a in addrs:
|
||||
try:
|
||||
|
@ -181,7 +186,7 @@ proc connect*(
|
|||
tlsFlags,
|
||||
tlsMinVersion,
|
||||
tlsMaxVersion,
|
||||
hostName = hostPort[0])
|
||||
hostName = wantedHostName)
|
||||
|
||||
return conn
|
||||
except TransportError as exc:
|
||||
|
|
|
@ -122,9 +122,10 @@ proc connect*(
|
|||
let
|
||||
rng = if isNil(rng): newRng() else: rng
|
||||
key = Base64Pad.encode(genWebSecKey(rng))
|
||||
hostname = if hostName.len > 0: hostName else: $host
|
||||
|
||||
let client = if secure:
|
||||
await TlsHttpClient.connect(host, tlsFlags = flags)
|
||||
await TlsHttpClient.connect(host, tlsFlags = flags, hostName = hostname)
|
||||
else:
|
||||
await HttpClient.connect(host)
|
||||
|
||||
|
@ -134,7 +135,7 @@ proc connect*(
|
|||
("Cache-Control", "no-cache"),
|
||||
("Sec-WebSocket-Version", $version),
|
||||
("Sec-WebSocket-Key", key),
|
||||
("Host", if hostName.len > 0: hostName else: $host)]
|
||||
("Host", hostname)]
|
||||
|
||||
var headers = HttpTable.init(headerData)
|
||||
if protocols.len > 0:
|
||||
|
|
Loading…
Reference in New Issue