diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2016-09-18 18:16:51 +0200 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2016-09-18 18:16:51 +0200 |
commit | 3ad368f8cad42e45cc3d7c7987b81abdb299a0ff (patch) | |
tree | 2395199c7d6ec633ca983c2547bf746a5852b8b3 /tests | |
parent | 1740619c0cd3f94c2fe16560d44402daca449e53 (diff) | |
download | Nim-3ad368f8cad42e45cc3d7c7987b81abdb299a0ff.tar.gz |
Improvements to httpclient. Refs #4423.
* Adds ability to query HttpCode and compare it with strings. * Moves HttpMethod to HttpCore module. * Implements synchronous HttpClient using {.multisync.}.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/thttpclient.nim | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/stdlib/thttpclient.nim b/tests/stdlib/thttpclient.nim new file mode 100644 index 000000000..ced39d9c9 --- /dev/null +++ b/tests/stdlib/thttpclient.nim @@ -0,0 +1,53 @@ +import strutils + +import httpclient, asyncdispatch + +proc asyncTest() {.async.} = + var client = newAsyncHttpClient() + var resp = await client.request("http://example.com/") + doAssert(resp.code.is2xx) + doAssert("<title>Example Domain</title>" in resp.body) + + resp = await client.request("http://example.com/404") + doAssert(resp.code.is4xx) + doAssert(resp.code == Http404) + doAssert(resp.status == Http404) + + resp = await client.request("https://google.com/") + doAssert(resp.code.is2xx or resp.code.is3xx) + +proc syncTest() = + var client = newHttpClient() + var resp = client.request("http://example.com/") + doAssert(resp.code.is2xx) + doAssert("<title>Example Domain</title>" in resp.body) + + resp = client.request("http://example.com/404") + doAssert(resp.code.is4xx) + doAssert(resp.code == Http404) + doAssert(resp.status == Http404) + + resp = client.request("https://google.com/") + doAssert(resp.code.is2xx or resp.code.is3xx) + +syncTest() + +waitFor(asyncTest()) + +#[ + + else: + #downloadFile("http://force7.de/nim/index.html", "nimindex.html") + #downloadFile("http://www.httpwatch.com/", "ChunkTest.html") + #downloadFile("http://validator.w3.org/check?uri=http%3A%2F%2Fgoogle.com", + # "validator.html") + + #var r = get("http://validator.w3.org/check?uri=http%3A%2F%2Fgoogle.com& + # charset=%28detect+automatically%29&doctype=Inline&group=0") + + var data = newMultipartData() + data["output"] = "soap12" + data["uploaded_file"] = ("test.html", "text/html", + "<html><head></head><body><p>test</p></body></html>") + + echo postContent("http://validator.w3.org/check", multipart=data)]# |