summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJuan Carlos <juancarlospaco@gmail.com>2020-01-21 15:34:47 -0300
committerAndreas Rumpf <rumpf_a@web.de>2020-01-21 19:34:47 +0100
commit2fad7f134fa8cf871cdf6ccdcedc6df0d62c2f64 (patch)
tree78c0b2ed1d8889e1cea4662909422317ce5ed7ca
parentbdb7c82c6aaf60392285cfea43c65c5b9b919e27 (diff)
downloadNim-2fad7f134fa8cf871cdf6ccdcedc6df0d62c2f64.tar.gz
httpclient, maxredirects to Natural, newHttpClient/newAsyncHttpClient add headers argument instead of hardcoded empty (#13207)
-rw-r--r--changelog.md3
-rw-r--r--lib/pure/httpclient.nim14
2 files changed, 12 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 71a77b86f..7e08133a0 100644
--- a/changelog.md
+++ b/changelog.md
@@ -68,6 +68,9 @@
 - `htmlgen.html` allows `lang` on the `<html>` tag and common valid attributes.
 - `macros.basename` and `basename=` got support for `PragmaExpr`,
   so that an expression like `MyEnum {.pure.}` is handled correctly.
+- `httpclient.maxredirects` changed from `int` to `Natural`, because negative values serve no purpose whatsoever.
+- `httpclient.newHttpClient` and `httpclient.newAsyncHttpClient` added `headers` argument to set initial HTTP Headers,
+  instead of a hardcoded empty `newHttpHeader()`.
 
 
 ## Language additions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index d9a6192a7..7c062c2e1 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -486,7 +486,7 @@ type
     connected: bool
     currentURL: Uri       ## Where we are currently connected.
     headers*: HttpHeaders ## Headers to send in requests.
-    maxRedirects: int
+    maxRedirects: Natural ## Maximum redirects, set to ``0`` to disable.
     userAgent: string
     timeout*: int         ## Only used for blocking HttpClient for now.
     proxy: Proxy
@@ -513,7 +513,7 @@ type
 
 proc newHttpClient*(userAgent = defUserAgent,
     maxRedirects = 5, sslContext = getDefaultSSL(), proxy: Proxy = nil,
-    timeout = -1): HttpClient =
+    timeout = -1, headers = newHttpHeaders()): HttpClient =
   ## Creates a new HttpClient instance.
   ##
   ## ``userAgent`` specifies the user agent that will be used when making
@@ -529,8 +529,10 @@ proc newHttpClient*(userAgent = defUserAgent,
   ##
   ## ``timeout`` specifies the number of milliseconds to allow before a
   ## ``TimeoutError`` is raised.
+  ##
+  ## ``headers`` specifies the HTTP Headers.
   new result
-  result.headers = newHttpHeaders()
+  result.headers = headers
   result.userAgent = userAgent
   result.maxRedirects = maxRedirects
   result.proxy = proxy
@@ -546,7 +548,7 @@ type
 
 proc newAsyncHttpClient*(userAgent = defUserAgent,
     maxRedirects = 5, sslContext = getDefaultSSL(),
-    proxy: Proxy = nil): AsyncHttpClient =
+    proxy: Proxy = nil, headers = newHttpHeaders()): AsyncHttpClient =
   ## Creates a new AsyncHttpClient instance.
   ##
   ## ``userAgent`` specifies the user agent that will be used when making
@@ -559,8 +561,10 @@ proc newAsyncHttpClient*(userAgent = defUserAgent,
   ##
   ## ``proxy`` specifies an HTTP proxy to use for this HTTP client's
   ## connections.
+  ##
+  ## ``headers`` specifies the HTTP Headers.
   new result
-  result.headers = newHttpHeaders()
+  result.headers = headers
   result.userAgent = userAgent
   result.maxRedirects = maxRedirects
   result.proxy = proxy