|
1 | | -app_httr_get <- function(self, private, url, fn_404 = NULL) { |
| 1 | +app_httr2_get <- function(self, private, url, fn_404 = NULL) { |
2 | 2 | ckm8_assert_app_driver(self, private) |
3 | 3 |
|
4 | | - pieces <- httr::parse_url(url) |
| 4 | + pieces <- httr2::url_parse(url) |
5 | 5 | # Add in port information if it's missing |
6 | 6 | # https://github.com/rstudio/shinytest2/issues/158 |
7 | 7 | if (is.null(pieces$port)) { |
8 | 8 | pieces$port <- switch(pieces$scheme, "http" = 80, "https" = 443) |
9 | 9 | } |
10 | 10 |
|
11 | 11 | if (!pingr::is_up(pieces$hostname, pieces$port, check_online = FALSE)) { |
12 | | - app_abort(self, private, "Could not find Shiny server. Shiny app is no longer running") |
| 12 | + app_abort( |
| 13 | + self, |
| 14 | + private, |
| 15 | + "Could not find Shiny server. Shiny app is no longer running" |
| 16 | + ) |
13 | 17 | } |
14 | 18 |
|
15 | | - withCallingHandlers( # abort() on error |
16 | | - { # nolint |
17 | | - req <- httr::GET(url) |
| 19 | + withCallingHandlers( |
| 20 | + # abort() on error |
| 21 | + { |
| 22 | + # nolint |
| 23 | + req <- httr2::request(url) |
| 24 | + req <- httr2::req_error(req, is_error = function(resp) FALSE) |
| 25 | + req <- httr2::req_perform(req) |
18 | 26 | }, |
19 | 27 | # Attempt to capture empty reply error and provide better message |
20 | 28 | error = function(e) { |
21 | 29 | if (grepl("Empty reply from server", as.character(e), fixed = TRUE)) { |
22 | | - app_abort(self, private, "Empty reply received from Shiny server. Shiny app is no longer running", parent = e) |
| 30 | + app_abort( |
| 31 | + self, |
| 32 | + private, |
| 33 | + "Empty reply received from Shiny server. Shiny app is no longer running", |
| 34 | + parent = e |
| 35 | + ) |
23 | 36 | } |
24 | 37 | # Unknown error, rethrow |
25 | 38 | app_abort(self, private, e) |
26 | 39 | } |
27 | 40 | ) |
28 | 41 |
|
29 | | - status <- httr::status_code(req) |
| 42 | + status <- httr2::resp_status(req) |
30 | 43 | if (status == 200) { |
31 | 44 | return(req) |
32 | 45 | } |
33 | 46 | if (status == 404 && is.function(fn_404)) { |
34 | 47 | return(fn_404(req)) |
35 | 48 | } |
36 | 49 |
|
37 | | - cat("{shinytest2} query failed (", status, ")----------------------\n", sep = "") |
| 50 | + cat( |
| 51 | + "{shinytest2} query failed (", |
| 52 | + status, |
| 53 | + ")----------------------\n", |
| 54 | + sep = "" |
| 55 | + ) |
38 | 56 | cat("URL: ", url, "\n", sep = "") |
39 | | - cat(httr::content(req, "text"), "\n") |
| 57 | + cat(httr2::resp_body_string(req), "\n") |
40 | 58 | cat("----------------------------------------\n") |
41 | 59 | app_abort(self, private, "Unable request data from server") |
42 | 60 | } |
0 commit comments