Catch SSL shutdown errors when closing clients
This commit is contained in:
parent
b09798f2cf
commit
ee43d8cfb1
|
@ -26,7 +26,9 @@ proc genHeaders*(agent: string; referer: Uri; lang=true;
|
||||||
|
|
||||||
template newClient*() {.dirty.} =
|
template newClient*() {.dirty.} =
|
||||||
var client = newAsyncHttpClient()
|
var client = newAsyncHttpClient()
|
||||||
defer: client.close()
|
defer:
|
||||||
|
try: client.close()
|
||||||
|
except: discard
|
||||||
client.headers = headers
|
client.headers = headers
|
||||||
|
|
||||||
proc fetchHtml*(url: Uri; headers: HttpHeaders; jsonKey = ""): Future[XmlNode] {.async.} =
|
proc fetchHtml*(url: Uri; headers: HttpHeaders; jsonKey = ""): Future[XmlNode] {.async.} =
|
||||||
|
|
|
@ -31,7 +31,7 @@ proc createMediaRouter*(cfg: Config) =
|
||||||
let client = newAsyncHttpClient()
|
let client = newAsyncHttpClient()
|
||||||
try:
|
try:
|
||||||
await client.downloadFile($uri, filename)
|
await client.downloadFile($uri, filename)
|
||||||
client.close()
|
client.safeClose()
|
||||||
except HttpRequestError:
|
except HttpRequestError:
|
||||||
removeFile(filename)
|
removeFile(filename)
|
||||||
resp Http404
|
resp Http404
|
||||||
|
|
|
@ -2,6 +2,8 @@ import strutils, sequtils, asyncdispatch, httpclient
|
||||||
import ../utils, ../prefs
|
import ../utils, ../prefs
|
||||||
export utils, prefs
|
export utils, prefs
|
||||||
|
|
||||||
|
from net import SslError
|
||||||
|
|
||||||
template cookiePrefs*(): untyped {.dirty.} =
|
template cookiePrefs*(): untyped {.dirty.} =
|
||||||
getPrefs(request.cookies.getOrDefault("preferences"), cfg)
|
getPrefs(request.cookies.getOrDefault("preferences"), cfg)
|
||||||
|
|
||||||
|
@ -14,8 +16,12 @@ template refPath*(): untyped {.dirty.} =
|
||||||
proc getNames*(name: string): seq[string] =
|
proc getNames*(name: string): seq[string] =
|
||||||
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||||
|
|
||||||
|
proc safeClose*(client: AsyncHttpClient) =
|
||||||
|
try: client.close()
|
||||||
|
except SslError: discard
|
||||||
|
|
||||||
proc safeFetch*(url: string): Future[string] {.async.} =
|
proc safeFetch*(url: string): Future[string] {.async.} =
|
||||||
let client = newAsyncHttpClient()
|
let client = newAsyncHttpClient()
|
||||||
try: result = await client.getContent(url)
|
try: result = await client.getContent(url)
|
||||||
except: discard
|
except: discard
|
||||||
client.close()
|
client.safeClose()
|
||||||
|
|
Loading…
Reference in New Issue