httpclient, maxredirects to Natural, newHttpClient/newAsyncHttpClient add headers argument instead of hardcoded empty (#13207)
This commit is contained in:
parent
bdb7c82c6a
commit
2fad7f134f
2 changed files with 12 additions and 5 deletions
|
|
@ -68,6 +68,9 @@
|
||||||
- `htmlgen.html` allows `lang` on the `<html>` tag and common valid attributes.
|
- `htmlgen.html` allows `lang` on the `<html>` tag and common valid attributes.
|
||||||
- `macros.basename` and `basename=` got support for `PragmaExpr`,
|
- `macros.basename` and `basename=` got support for `PragmaExpr`,
|
||||||
so that an expression like `MyEnum {.pure.}` is handled correctly.
|
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
|
## Language additions
|
||||||
|
|
|
||||||
|
|
@ -486,7 +486,7 @@ type
|
||||||
connected: bool
|
connected: bool
|
||||||
currentURL: Uri ## Where we are currently connected.
|
currentURL: Uri ## Where we are currently connected.
|
||||||
headers*: HttpHeaders ## Headers to send in requests.
|
headers*: HttpHeaders ## Headers to send in requests.
|
||||||
maxRedirects: int
|
maxRedirects: Natural ## Maximum redirects, set to ``0`` to disable.
|
||||||
userAgent: string
|
userAgent: string
|
||||||
timeout*: int ## Only used for blocking HttpClient for now.
|
timeout*: int ## Only used for blocking HttpClient for now.
|
||||||
proxy: Proxy
|
proxy: Proxy
|
||||||
|
|
@ -513,7 +513,7 @@ type
|
||||||
|
|
||||||
proc newHttpClient*(userAgent = defUserAgent,
|
proc newHttpClient*(userAgent = defUserAgent,
|
||||||
maxRedirects = 5, sslContext = getDefaultSSL(), proxy: Proxy = nil,
|
maxRedirects = 5, sslContext = getDefaultSSL(), proxy: Proxy = nil,
|
||||||
timeout = -1): HttpClient =
|
timeout = -1, headers = newHttpHeaders()): HttpClient =
|
||||||
## Creates a new HttpClient instance.
|
## Creates a new HttpClient instance.
|
||||||
##
|
##
|
||||||
## ``userAgent`` specifies the user agent that will be used when making
|
## ``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
|
## ``timeout`` specifies the number of milliseconds to allow before a
|
||||||
## ``TimeoutError`` is raised.
|
## ``TimeoutError`` is raised.
|
||||||
|
##
|
||||||
|
## ``headers`` specifies the HTTP Headers.
|
||||||
new result
|
new result
|
||||||
result.headers = newHttpHeaders()
|
result.headers = headers
|
||||||
result.userAgent = userAgent
|
result.userAgent = userAgent
|
||||||
result.maxRedirects = maxRedirects
|
result.maxRedirects = maxRedirects
|
||||||
result.proxy = proxy
|
result.proxy = proxy
|
||||||
|
|
@ -546,7 +548,7 @@ type
|
||||||
|
|
||||||
proc newAsyncHttpClient*(userAgent = defUserAgent,
|
proc newAsyncHttpClient*(userAgent = defUserAgent,
|
||||||
maxRedirects = 5, sslContext = getDefaultSSL(),
|
maxRedirects = 5, sslContext = getDefaultSSL(),
|
||||||
proxy: Proxy = nil): AsyncHttpClient =
|
proxy: Proxy = nil, headers = newHttpHeaders()): AsyncHttpClient =
|
||||||
## Creates a new AsyncHttpClient instance.
|
## Creates a new AsyncHttpClient instance.
|
||||||
##
|
##
|
||||||
## ``userAgent`` specifies the user agent that will be used when making
|
## ``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
|
## ``proxy`` specifies an HTTP proxy to use for this HTTP client's
|
||||||
## connections.
|
## connections.
|
||||||
|
##
|
||||||
|
## ``headers`` specifies the HTTP Headers.
|
||||||
new result
|
new result
|
||||||
result.headers = newHttpHeaders()
|
result.headers = headers
|
||||||
result.userAgent = userAgent
|
result.userAgent = userAgent
|
||||||
result.maxRedirects = maxRedirects
|
result.maxRedirects = maxRedirects
|
||||||
result.proxy = proxy
|
result.proxy = proxy
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue