make httpclient close opened Socket on error
This commit is contained in:
parent
b9865e8ad0
commit
b0f1d9f467
1 changed files with 26 additions and 21 deletions
|
|
@ -422,7 +422,9 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
add(headers, "Proxy-Authorization: basic " & auth & "\c\L")
|
add(headers, "Proxy-Authorization: basic " & auth & "\c\L")
|
||||||
add(headers, extraHeaders)
|
add(headers, extraHeaders)
|
||||||
add(headers, "\c\L")
|
add(headers, "\c\L")
|
||||||
var s = newSocket()
|
var s: Socket
|
||||||
|
try:
|
||||||
|
s = newSocket()
|
||||||
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,6 +446,9 @@ 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)
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue