summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-07-28 20:54:58 +0200
committerGitHub <noreply@github.com>2016-07-28 20:54:58 +0200
commitd7a1abd5f7b88e2081276d712fcf4a94fa4d5e8b (patch)
treef193c2a1d8e262e35d63e58a0f8940060d623cc2 /lib/pure
parentccae58c5e2200052d410458732c34eab63423b4b (diff)
parent4bef9d020d8ca974c376ae1213e083b20ebf29ab (diff)
downloadNim-d7a1abd5f7b88e2081276d712fcf4a94fa4d5e8b.tar.gz
Merge pull request #4527 from hendi/httpclient-close-sockets
make httpclient close opened Socket on error
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/httpclient.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index bc964861d..37bc5d8f4 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -423,6 +423,7 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
   add(headers, extraHeaders)
   add(headers, "\c\L")
   var s = newSocket()
+  defer: s.close()
   if s == nil: raiseOSError(osLastError())
   var port = net.Port(80)
   if r.scheme == "https":
@@ -444,7 +445,6 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
     s.send(body)
 
   result = parseResponse(s, httpMethod != "httpHEAD", timeout)
-  s.close()
 
 proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
               body = "", sslContext = defaultSSLContext, timeout = -1,