Merge pull request #4527 from hendi/httpclient-close-sockets
make httpclient close opened Socket on error
This commit is contained in:
commit
d7a1abd5f7
1 changed files with 1 additions and 1 deletions
|
|
@ -423,6 +423,7 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
add(headers, extraHeaders)
|
add(headers, extraHeaders)
|
||||||
add(headers, "\c\L")
|
add(headers, "\c\L")
|
||||||
var s = newSocket()
|
var s = newSocket()
|
||||||
|
defer: s.close()
|
||||||
if s == nil: raiseOSError(osLastError())
|
if s == nil: raiseOSError(osLastError())
|
||||||
var port = net.Port(80)
|
var port = net.Port(80)
|
||||||
if r.scheme == "https":
|
if r.scheme == "https":
|
||||||
|
|
@ -444,7 +445,6 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
s.send(body)
|
s.send(body)
|
||||||
|
|
||||||
result = parseResponse(s, httpMethod != "httpHEAD", timeout)
|
result = parseResponse(s, httpMethod != "httpHEAD", timeout)
|
||||||
s.close()
|
|
||||||
|
|
||||||
proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
||||||
body = "", sslContext = defaultSSLContext, timeout = -1,
|
body = "", sslContext = defaultSSLContext, timeout = -1,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue