Skip to content

Commit

Permalink
Timeout argument (#7)
Browse files Browse the repository at this point in the history
* timeout param

* docs and version
  • Loading branch information
mishankov authored Dec 3, 2023
1 parent db6fe3e commit 7039ec4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/yahttp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/yahttp/internal/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion yahttp.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.5.1"
version = "0.6.0"
author = "Denis Mishankov"
description = "Awesome simple HTTP client"
license = "MIT"
Expand Down

0 comments on commit 7039ec4

Please sign in to comment.