use defer instead of try ... finally
This commit is contained in:
parent
6a2ad716a4
commit
4bef9d020d
1 changed files with 21 additions and 24 deletions
|
|
@ -422,9 +422,8 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
|||
add(headers, "Proxy-Authorization: basic " & auth & "\c\L")
|
||||
add(headers, extraHeaders)
|
||||
add(headers, "\c\L")
|
||||
var s: Socket
|
||||
try:
|
||||
s = newSocket()
|
||||
var s = newSocket()
|
||||
defer: s.close()
|
||||
if s == nil: raiseOSError(osLastError())
|
||||
var port = net.Port(80)
|
||||
if r.scheme == "https":
|
||||
|
|
@ -446,8 +445,6 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
|||
s.send(body)
|
||||
|
||||
result = parseResponse(s, httpMethod != "httpHEAD", timeout)
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
||||
body = "", sslContext = defaultSSLContext, timeout = -1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue