Skip to content

Commit 2fad7f1

Browse files
juancarlospacoAraq
authored andcommitted
httpclient, maxredirects to Natural, newHttpClient/newAsyncHttpClient add headers argument instead of hardcoded empty (#13207)
1 parent bdb7c82 commit 2fad7f1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
- `htmlgen.html` allows `lang` on the `<html>` tag and common valid attributes.
6969
- `macros.basename` and `basename=` got support for `PragmaExpr`,
7070
so that an expression like `MyEnum {.pure.}` is handled correctly.
71+
- `httpclient.maxredirects` changed from `int` to `Natural`, because negative values serve no purpose whatsoever.
72+
- `httpclient.newHttpClient` and `httpclient.newAsyncHttpClient` added `headers` argument to set initial HTTP Headers,
73+
instead of a hardcoded empty `newHttpHeader()`.
7174

7275

7376
## Language additions

lib/pure/httpclient.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ type
486486
connected: bool
487487
currentURL: Uri ## Where we are currently connected.
488488
headers*: HttpHeaders ## Headers to send in requests.
489-
maxRedirects: int
489+
maxRedirects: Natural ## Maximum redirects, set to ``0`` to disable.
490490
userAgent: string
491491
timeout*: int ## Only used for blocking HttpClient for now.
492492
proxy: Proxy
@@ -513,7 +513,7 @@ type
513513

514514
proc newHttpClient*(userAgent = defUserAgent,
515515
maxRedirects = 5, sslContext = getDefaultSSL(), proxy: Proxy = nil,
516-
timeout = -1): HttpClient =
516+
timeout = -1, headers = newHttpHeaders()): HttpClient =
517517
## Creates a new HttpClient instance.
518518
##
519519
## ``userAgent`` specifies the user agent that will be used when making
@@ -529,8 +529,10 @@ proc newHttpClient*(userAgent = defUserAgent,
529529
##
530530
## ``timeout`` specifies the number of milliseconds to allow before a
531531
## ``TimeoutError`` is raised.
532+
##
533+
## ``headers`` specifies the HTTP Headers.
532534
new result
533-
result.headers = newHttpHeaders()
535+
result.headers = headers
534536
result.userAgent = userAgent
535537
result.maxRedirects = maxRedirects
536538
result.proxy = proxy
@@ -546,7 +548,7 @@ type
546548

547549
proc newAsyncHttpClient*(userAgent = defUserAgent,
548550
maxRedirects = 5, sslContext = getDefaultSSL(),
549-
proxy: Proxy = nil): AsyncHttpClient =
551+
proxy: Proxy = nil, headers = newHttpHeaders()): AsyncHttpClient =
550552
## Creates a new AsyncHttpClient instance.
551553
##
552554
## ``userAgent`` specifies the user agent that will be used when making
@@ -559,8 +561,10 @@ proc newAsyncHttpClient*(userAgent = defUserAgent,
559561
##
560562
## ``proxy`` specifies an HTTP proxy to use for this HTTP client's
561563
## connections.
564+
##
565+
## ``headers`` specifies the HTTP Headers.
562566
new result
563-
result.headers = newHttpHeaders()
567+
result.headers = headers
564568
result.userAgent = userAgent
565569
result.maxRedirects = maxRedirects
566570
result.proxy = proxy

0 commit comments

Comments
 (0)