diff --git a/README.md b/README.md index 989282c..1e9487c 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Arguments: - `encodeQueryParams` - parameters for `encodeQuery` function that encodes query params. [More](https://nim-lang.org/docs/uri.html#encodeQuery%2CopenArray%5B%5D%2Cchar) - `body` - request body as a string. Example: `"{\"key\": \"value\"}\"`. Is not available for `get`, `head` and `options` procedures - `auth` - login and password for basic authorization. Example: `("login", "password")` +- `timeout` - stop waiting for a response after a given number of milliseconds. `-1` for no timeout, which is default value - `ignoreSsl` - no certificate verification if `true` ## General procedure diff --git a/src/yahttp.nim b/src/yahttp.nim index 555b7e4..1e6ebb4 100644 --- a/src/yahttp.nim +++ b/src/yahttp.nim @@ -68,15 +68,15 @@ proc request*(url: string, httpMethod: Method = Method.GET, headers: openArray[ RequestHeader] = [], query: openArray[QueryParam] = [], encodeQueryParams: EncodeQueryParams = defaultEncodeQueryParams, body: string = "", - auth: BasicAuth = ("", ""), ignoreSsl = false): Response = + auth: BasicAuth = ("", ""), timeout = -1, ignoreSsl = false): Response = ## Genreal proc to make HTTP request with every HTTP method # Prepare client let client: HttpClient = if ignoreSsl: - newHttpClient(sslContext = newContext(verifyMode = CVerifyNone)) + newHttpClient(timeout = timeout, sslContext = newContext(verifyMode = CVerifyNone)) else: - newHttpClient() + newHttpClient(timeout = timeout) # Prepare headers diff --git a/src/yahttp/internal/utils.nim b/src/yahttp/internal/utils.nim index 7443400..a21ab40 100644 --- a/src/yahttp/internal/utils.nim +++ b/src/yahttp/internal/utils.nim @@ -6,7 +6,7 @@ macro http_method_gen*(name: untyped): untyped = let comment = newCommentStmtNode(fmt"Proc for {methodUpper} HTTP method") quote do: proc `name`*(url: string, headers: openArray[RequestHeader] = [], query: openArray[ - QueryParam] = [], encodeQueryParams: EncodeQueryParams = defaultEncodeQueryParams, body: string = "", auth: BasicAuth = ("", ""), + QueryParam] = [], encodeQueryParams: EncodeQueryParams = defaultEncodeQueryParams, body: string = "", auth: BasicAuth = ("", ""), timeout = -1, ignoreSsl = false): Response = `comment` return request( @@ -26,7 +26,7 @@ macro http_method_no_body_gen*(name: untyped): untyped = let comment = newCommentStmtNode(fmt"Proc for {methodUpper} HTTP method") quote do: proc `name`*(url: string, headers: openArray[RequestHeader] = [], query: openArray[ - QueryParam] = [], encodeQueryParams: EncodeQueryParams = defaultEncodeQueryParams, auth: BasicAuth = ("", ""), ignoreSsl = false): Response = + QueryParam] = [], encodeQueryParams: EncodeQueryParams = defaultEncodeQueryParams, auth: BasicAuth = ("", ""), timeout = -1, ignoreSsl = false): Response = `comment` return request( url = url, diff --git a/yahttp.nimble b/yahttp.nimble index 5bdbe89..ae0e2b7 100644 --- a/yahttp.nimble +++ b/yahttp.nimble @@ -1,6 +1,6 @@ # Package -version = "0.5.1" +version = "0.6.0" author = "Denis Mishankov" description = "Awesome simple HTTP client" license = "MIT"