Skip to content

Commit 666e0d6

Browse files
hadleyjennybc
andauthored
Switch to httr2 (#2642)
* Switch to httr2 Fixes #2602 * Polishing --------- Co-authored-by: Jenny Bryan <jenny.f.bryan@gmail.com>
1 parent df36e83 commit 666e0d6

5 files changed

Lines changed: 27 additions & 46 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Suggests:
4747
DT (>= 0.23),
4848
foghorn (>= 1.4.2),
4949
gh (>= 1.3.0),
50-
httr (>= 1.4.3),
50+
httr2 (>= 1.0.0),
5151
knitr (>= 1.39),
5252
lintr (>= 3.0.0),
5353
remotes (>= 2.5.0),

R/check-mac.R

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,24 @@ check_mac <- function(
100100

101101
url <- "https://mac.r-project.org/macbuilder/v1/submit"
102102

103-
check_installed("httr")
103+
check_installed("httr2")
104104
body <- list(
105-
pkgfile = httr::upload_file(built_path),
105+
pkgfile = curl::form_file(built_path),
106106
rflavor = tolower(version)
107107
)
108108

109109
if (length(dep_built_paths) > 0) {
110-
uploads <- map(dep_built_paths, httr::upload_file)
110+
uploads <- map(dep_built_paths, curl::form_file)
111111
names(uploads) <- rep("depfiles", length(uploads))
112112
body <- append(body, uploads)
113113
}
114114

115-
res <- httr::POST(
116-
url,
117-
body = body,
118-
headers = list(
119-
"Content-Type" = "multipart/form-data"
120-
),
121-
encode = "multipart"
122-
)
123-
124-
httr::stop_for_status(res, task = "Uploading package")
115+
req <- httr2::request(url) |>
116+
httr2::req_body_multipart(!!!body) |>
117+
httr2::req_headers(Accept = "application/json")
118+
resp <- httr2::req_perform(req)
125119

126-
response_url <- httr::content(res)$url
120+
response_url <- httr2::resp_body_json(resp)$url
127121

128122
if (!quiet) {
129123
time <- strftime(Sys.time() + 10 * 60, "%I:%M %p")

R/release.R

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -289,54 +289,42 @@ extract_cran_msg <- function(msg) {
289289
}
290290

291291
upload_cran <- function(pkg, built_path, call = parent.frame()) {
292+
check_installed("httr2")
293+
292294
pkg <- as.package(pkg)
293295
maint <- maintainer(pkg)
294296
comments <- cran_comments(pkg, call = call)
295297

296298
# Initial upload ---------
297299
cli::cli_inform(c(i = "Uploading package & comments"))
298-
check_installed("httr")
299-
body <- list(
300+
req <- httr2::request(cran_submission_url)
301+
req <- httr2::req_body_multipart(
302+
req,
300303
pkg_id = "",
301304
name = maint$name,
302305
email = maint$email,
303-
uploaded_file = httr::upload_file(built_path, "application/x-gzip"),
306+
uploaded_file = curl::form_file(built_path, "application/x-gzip"),
304307
comment = comments,
305308
upload = "Upload package"
306309
)
307-
r <- httr::POST(cran_submission_url, body = body)
308-
309-
# If a 404 likely CRAN is closed for maintenance, try to get the message
310-
if (httr::status_code(r) == 404) {
311-
msg <- ""
312-
try({
313-
r2 <- httr::GET(sub("index2", "index", cran_submission_url))
314-
msg <- extract_cran_msg(httr::content(r2, "text"))
315-
})
316-
cli::cli_abort(
317-
c(
318-
"*" = "Submission failed",
319-
"x" = msg
320-
),
321-
call = call
322-
)
323-
}
324-
325-
httr::stop_for_status(r)
326-
new_url <- httr::parse_url(r$url)
310+
resp <- httr2::req_perform(req)
311+
new_url <- httr2::url_parse(httr2::resp_url(resp))
327312

328313
# Confirmation -----------
329314
cli::cli_inform(c(i = "Confirming submission"))
330-
body <- list(
315+
316+
req <- httr2::request(cran_submission_url)
317+
req <- httr2::req_body_multipart(
318+
req,
331319
pkg_id = new_url$query$pkg_id,
332320
name = maint$name,
333321
email = maint$email,
334322
policy_check = "1/",
335323
submit = "Submit package"
336324
)
337-
r <- httr::POST(cran_submission_url, body = body)
338-
httr::stop_for_status(r)
339-
new_url <- httr::parse_url(r$url)
325+
326+
resp <- httr2::req_perform(req)
327+
new_url <- httr2::url_parse(httr2::resp_url(resp))
340328
if (new_url$query$submit == "1") {
341329
cli::cli_inform(c(
342330
"v" = "Package submission successful",

R/run-source.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@
3030
#' }
3131
source_url <- function(url, ..., sha1 = NULL) {
3232
check_string(url)
33-
check_installed(c("digest", "httr"))
33+
check_installed(c("digest", "httr2"))
3434

3535
temp_file <- file_temp()
3636
on.exit(file_delete(temp_file), add = TRUE)
3737

38-
request <- httr::GET(url)
39-
httr::stop_for_status(request)
40-
writeBin(httr::content(request, type = "raw"), temp_file)
38+
httr2::req_perform(httr2::request(url), path = temp_file)
4139

4240
check_sha1(temp_file, sha1)
4341

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ hadley
9999
http
100100
https
101101
httr
102+
httr2
102103
hunspell
103104
importFrom
104105
initialising

0 commit comments

Comments
 (0)