switched httpclient to use net module instead of sockets
This commit is contained in:
parent
8be177627a
commit
7a7fe85f85
1 changed files with 6 additions and 7 deletions
|
|
@ -88,10 +88,9 @@
|
||||||
## constructor should be used for this purpose. However,
|
## constructor should be used for this purpose. However,
|
||||||
## currently only basic authentication is supported.
|
## currently only basic authentication is supported.
|
||||||
|
|
||||||
import sockets, strutils, parseurl, parseutils, strtabs, base64, os
|
import net, strutils, parseurl, parseutils, strtabs, base64, os
|
||||||
import asyncnet, asyncdispatch
|
import asyncnet, asyncdispatch
|
||||||
import rawsockets
|
import rawsockets
|
||||||
from net import nil
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Response* = tuple[
|
Response* = tuple[
|
||||||
|
|
@ -308,18 +307,18 @@ proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
||||||
add(headers, extraHeaders)
|
add(headers, extraHeaders)
|
||||||
add(headers, "\c\L")
|
add(headers, "\c\L")
|
||||||
|
|
||||||
var s = socket()
|
var s = newSocket()
|
||||||
if s == invalidSocket: raiseOSError(osLastError())
|
if s == nil: raiseOSError(osLastError())
|
||||||
var port = sockets.Port(80)
|
var port = net.Port(80)
|
||||||
if r.scheme == "https":
|
if r.scheme == "https":
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
sslContext.wrapSocket(s)
|
sslContext.wrapSocket(s)
|
||||||
port = sockets.Port(443)
|
port = net.Port(443)
|
||||||
else:
|
else:
|
||||||
raise newException(HttpRequestError,
|
raise newException(HttpRequestError,
|
||||||
"SSL support is not available. Cannot connect over SSL.")
|
"SSL support is not available. Cannot connect over SSL.")
|
||||||
if r.port != "":
|
if r.port != "":
|
||||||
port = sockets.Port(r.port.parseInt)
|
port = net.Port(r.port.parseInt)
|
||||||
|
|
||||||
if timeout == -1:
|
if timeout == -1:
|
||||||
s.connect(r.hostname, port)
|
s.connect(r.hostname, port)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue