mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-02 12:04:44 +00:00
Httpclient improvements (#15919)
* Allow passing Uri instead of strings * Teach httpclient about 308 * Deprecate request proc where httpMethod is string * More use of HttpMethod enum Also fix handling of 308, I forgot to add the hunk to the previous commit. * Well behaved redirect handler * Also remove Transfer-Encoding * Removed unused proc * Secure redirection rules Strip sensitive headers for cross-domain redirects. * Allow httpMethod to be a string again This way unknown http verbs can be used without any problem. * Respect user-specified Host header * Missed multipart argument. * Try another method * add changelog * Fix hidden deprecation warning, parseEnum failing * This is wrong * Have to do it manually, parseEnum is not suitable * Review comments * update Co-authored-by: LemonBoy <thatlemon@gmail.com> Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
This commit is contained in:
@@ -39,7 +39,7 @@ proc makeIPv6HttpServer(hostname: string, port: Port,
|
||||
|
||||
proc asyncTest() {.async.} =
|
||||
var client = newAsyncHttpClient()
|
||||
var resp = await client.request("http://example.com/")
|
||||
var resp = await client.request("http://example.com/", HttpGet)
|
||||
doAssert(resp.code.is2xx)
|
||||
var body = await resp.body
|
||||
body = await resp.body # Test caching
|
||||
@@ -48,7 +48,7 @@ proc asyncTest() {.async.} =
|
||||
resp = await client.request("http://example.com/404")
|
||||
doAssert(resp.code.is4xx)
|
||||
doAssert(resp.code == Http404)
|
||||
doAssert(resp.status == Http404)
|
||||
doAssert(resp.status == $Http404)
|
||||
|
||||
resp = await client.request("https://google.com/")
|
||||
doAssert(resp.code.is2xx or resp.code.is3xx)
|
||||
@@ -102,14 +102,14 @@ proc asyncTest() {.async.} =
|
||||
|
||||
proc syncTest() =
|
||||
var client = newHttpClient()
|
||||
var resp = client.request("http://example.com/")
|
||||
var resp = client.request("http://example.com/", HttpGet)
|
||||
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)
|
||||
doAssert(resp.status == $Http404)
|
||||
|
||||
resp = client.request("https://google.com/")
|
||||
doAssert(resp.code.is2xx or resp.code.is3xx)
|
||||
|
||||
Reference in New Issue
Block a user