Implements timeouts for synchronous HttpClient.

This commit is contained in:
Dominik Picheta 2016-09-18 19:08:12 +02:00
commit 0c99523ad3
2 changed files with 35 additions and 9 deletions

View file

@ -1,4 +1,5 @@
import strutils
from net import TimeoutError
import httpclient, asyncdispatch
@ -30,6 +31,18 @@ proc syncTest() =
resp = client.request("https://google.com/")
doAssert(resp.code.is2xx or resp.code.is3xx)
client.close()
# Timeout test.
client = newHttpClient(timeout = 1)
try:
resp = client.request("http://example.com/")
doAssert false, "TimeoutError should have been raised."
except TimeoutError:
discard
except:
doAssert false, "TimeoutError should have been raised."
syncTest()
waitFor(asyncTest())