switched httpclient to use net module instead of sockets

This commit is contained in:
Will Szumski 2014-12-17 17:53:11 +00:00
commit 7a7fe85f85

View file

@ -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)