Skip to content

Commit

Permalink
Use same http options as pak/pkgcache
Browse files Browse the repository at this point in the history
In particular the path to the CA bundle, for
r-lib/pak#693.
  • Loading branch information
gaborcsardi committed Sep 24, 2024
1 parent d613795 commit b3f2aca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
18 changes: 18 additions & 0 deletions R/http.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
get_default_curl_options <- function(options) {
getopt <- function(nm) {
if (!is.null(v <- options[[nm]])) return(v)
anm <- paste0("async_http_", nm)
if (!is.null(v <- getOption(anm))) return(v)
if (!is.na(v <- Sys.getenv(toupper(anm), NA_character_))) return (v)
}
modifyList(
options,
drop_nulls(list(
timeout = as.integer(getopt("timeout") %||% 0),
connecttimeout = as.integer(getopt("connecttimeout") %||% 300),
low_speed_time = as.integer(getopt("low_speed_time") %||% 0),
low_speed_limit = as.integer(getopt("low_speed_limit") %||% 0),
cainfo = getopt("cainfo")
))
)
}

http_get <- function(url) {
curl::curl_fetch_memory(url)
Expand Down
18 changes: 11 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ contains <- function(x, y) y %in% x
isin <- function(x, y) x %in% y

remove_special <- function(list, level = 1) {

assert_that(is_positive_count(level))

if (level == 1) {
replace(
grepl(pattern = "^_", names(list)),
Expand All @@ -92,7 +92,7 @@ remove_special <- function(list, level = 1) {
} else {
lapply(list, remove_special, level = level - 1)
}

}

pluck <- function(list, idx) list[[idx]]
Expand All @@ -104,25 +104,25 @@ needs_packages <- function(pkgs) {

if (!all(has)) {
not_installed_pkgs <- pkgs[!has]

if (length(not_installed_pkgs) == 1) {

throw(new_error(
"The ",
sQuote(not_installed_pkgs),
" package is needed for this addin.",
call. = FALSE
))
} else {

throw(new_error(
"The ",
paste(sQuote(not_installed_pkgs), collapse = ", "),
" packages are needed for this addin.",
call. = FALSE
))
}

}
}

Expand All @@ -133,3 +133,7 @@ clean_description <- function(txt) {
zap_null <- function(x) {
x[! map_lgl(x, is.null)]
}

drop_nulls <- function (x) {
x[!map_lgl(x, is.null)]
}

0 comments on commit b3f2aca

Please sign in to comment.