Skip to content

Commit

Permalink
Merge pull request #125 from gladkia/customizable_timeout
Browse files Browse the repository at this point in the history
feat: add possibility to change the timeout for the curl's connect phase
  • Loading branch information
gaborcsardi authored Apr 22, 2024
2 parents 593cb84 + 5c0aed7 commit d613795
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 222 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pkgsearch (development version)

* pkgsearch now uses the `timeout` option to set the limit for the total
time of each HTTP request (#125, @gladkia).

# pkgsearch 3.1.3

* No user visible changes.
Expand Down
6 changes: 5 additions & 1 deletion R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ do_query <- function(query, server, from, size) {
check_count(from)
check_count(size)

# timeout for the curl's connect phase (in seconds)
timeout <- getOption("timeout", 60)

url <- server %+% "/package/_search?from=" %+%
as.character(from - 1) %+% "&size=" %+% as.character(size)
result <- http_post(
url, body = query,
headers = c("Content-Type" = "application/json"))
headers = c("Content-Type" = "application/json"),
options = list(timeout = timeout))
chain_error(
http_stop_for_status(result),
new_query_error(result, "search server failure")
Expand Down
9 changes: 9 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ ps("gabor", size = 5)
ps("Gábor", size = 5)
```

## Configuration

### Options

* `timeout`: pkgsearch follows the `timeout` options for HTTP requests
(i.e. for `pkg_search()` and `advanced_search()`. `timeout` is the limit
for the total time of the HTTP request, and it is in seconds. See
`?options` for details.

## More info

See the [complete documentation](https://r-hub.github.io/pkgsearch/).
Expand Down
Loading

0 comments on commit d613795

Please sign in to comment.