HTTP client's request proc no longer slices http method string param.
This commit is contained in:
parent
545e24b8ff
commit
6a83bc1ff5
2 changed files with 10 additions and 4 deletions
|
|
@ -649,7 +649,7 @@ proc downloadFile*(url: string, outputFilename: string,
|
||||||
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||||
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
||||||
# GET
|
# GET
|
||||||
result = substr(httpMethod, len("http")).toUpper()
|
result = httpMethod.toUpper()
|
||||||
result.add ' '
|
result.add ' '
|
||||||
|
|
||||||
if proxy.isNil:
|
if proxy.isNil:
|
||||||
|
|
@ -1010,14 +1010,15 @@ proc request*(client: HttpClient | AsyncHttpClient, url: string,
|
||||||
if not client.headers.hasKey("user-agent") and client.userAgent != "":
|
if not client.headers.hasKey("user-agent") and client.userAgent != "":
|
||||||
client.headers["User-Agent"] = client.userAgent
|
client.headers["User-Agent"] = client.userAgent
|
||||||
|
|
||||||
var headers = generateHeaders(requestUrl, $httpMethod,
|
var headers = generateHeaders(requestUrl, httpMethod,
|
||||||
client.headers, body, client.proxy)
|
client.headers, body, client.proxy)
|
||||||
|
|
||||||
await client.socket.send(headers)
|
await client.socket.send(headers)
|
||||||
if body != "":
|
if body != "":
|
||||||
await client.socket.send(body)
|
await client.socket.send(body)
|
||||||
|
|
||||||
result = await parseResponse(client, httpMethod notin {HttpHead, HttpConnect})
|
result = await parseResponse(client,
|
||||||
|
httpMethod.toLower() notin ["head", "connect"])
|
||||||
|
|
||||||
# Restore the clients proxy in case it was overwritten.
|
# Restore the clients proxy in case it was overwritten.
|
||||||
client.proxy = savedProxy
|
client.proxy = savedProxy
|
||||||
|
|
@ -1033,7 +1034,7 @@ proc request*(client: HttpClient | AsyncHttpClient, url: string,
|
||||||
##
|
##
|
||||||
## When a request is made to a different hostname, the current connection will
|
## When a request is made to a different hostname, the current connection will
|
||||||
## be closed.
|
## be closed.
|
||||||
result = await request(client, url, $httpMethod, body)
|
result = await request(client, url, substr($httpMethod, len("http")), body)
|
||||||
|
|
||||||
proc get*(client: HttpClient | AsyncHttpClient,
|
proc get*(client: HttpClient | AsyncHttpClient,
|
||||||
url: string): Future[Response] {.multisync.} =
|
url: string): Future[Response] {.multisync.} =
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ that have tuple name:
|
||||||
|
|
||||||
- ``AsyncHttpClient.headers`` type is now ``HttpHeaders``.
|
- ``AsyncHttpClient.headers`` type is now ``HttpHeaders``.
|
||||||
|
|
||||||
|
- The ``httpclient.request`` procedure that takes the ``httpMethod`` as a string
|
||||||
|
value no longer requires this value to be prefixed with ``"http"``
|
||||||
|
(or similar).
|
||||||
|
|
||||||
|
|
||||||
Library Additions
|
Library Additions
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue