Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ License: MIT + file LICENSE
URL: https://httr2.r-lib.org, https://github.com/r-lib/httr2
BugReports: https://github.com/r-lib/httr2/issues
Depends:
R (>= 4.0)
R (>= 4.1)
Imports:
cli (>= 3.0.0),
curl (>= 6.2.1),
Expand Down
6 changes: 1 addition & 5 deletions R/curl.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ curl_translate <- function(cmd, simplify_headers = TRUE) {
main_args = perform_args,
keep_if_empty = TRUE
)
out <- paste0(steps, collapse = paste0(pipe(), "\n "))
out <- paste0(steps, collapse = paste0(" |>\n "))

if (clip) {
cli::cli_alert_success("Copying to clipboard:")
Expand All @@ -109,10 +109,6 @@ curl_translate <- function(cmd, simplify_headers = TRUE) {
structure(out, class = "httr2_cmd")
}

pipe <- function() {
if (getRversion() >= "4.1.0") " |> " else " %>% "
}

#' @export
print.httr2_cmd <- function(x, ...) {
cat(x)
Expand Down
6 changes: 3 additions & 3 deletions R/iterate-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

if (!isTRUE(resp_complete(resp))) {
i <<- i + offset
req %>% req_url_query(!!param_name := i)
req |> req_url_query(!!param_name := i)

Check warning on line 86 in R/iterate-helpers.R

View check run for this annotation

Codecov / codecov/patch

R/iterate-helpers.R#L86

Added line #L86 was not covered by tests
}
}
}
Expand All @@ -100,7 +100,7 @@
function(resp, req) {
value <- resp_param_value(resp)
if (!is.null(value)) {
req %>% req_url_query(!!param_name := value)
req |> req_url_query(!!param_name := value)

Check warning on line 103 in R/iterate-helpers.R

View check run for this annotation

Codecov / codecov/patch

R/iterate-helpers.R#L103

Added line #L103 was not covered by tests
}
}
}
Expand All @@ -114,7 +114,7 @@
function(resp, req) {
url <- resp_link_url(resp, rel)
if (!is.null(url)) {
req %>% req_url(url)
req |> req_url(url)

Check warning on line 117 in R/iterate-helpers.R

View check run for this annotation

Codecov / codecov/patch

R/iterate-helpers.R#L117

Added line #L117 was not covered by tests
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/oauth-flow-auth-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
max_seconds = 60,
# The endpoint may temporarily return a 404 when no code is found for a
# given state because the user hasn't finished clicking through yet.
is_transient = ~ resp_status(.x) %in% c(404, 429, 503)
is_transient = \(resp) resp_status(resp) %in% c(404, 429, 503)

Check warning on line 495 in R/oauth-flow-auth-code.R

View check run for this annotation

Codecov / codecov/patch

R/oauth-flow-auth-code.R#L495

Added line #L495 was not covered by tests
)
resp <- req_perform(req)
body <- resp_body_json(resp)
Expand Down
2 changes: 1 addition & 1 deletion R/oauth-flow.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
oauth_flow_fetch <- function(req, source, error_call = caller_env()) {
req <- req_error(req, is_error = ~FALSE)
req <- req_error(req, is_error = \(resp) FALSE)
resp <- req_perform(req, error_call = current_call())

oauth_flow_parse(resp, source, error_call = error_call)
Expand Down
2 changes: 1 addition & 1 deletion R/resp-headers.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ resp_link_url <- function(resp, rel) {
link_headers <- headers[tolower(names(headers)) == "link"]

links <- unlist(lapply(link_headers, parse_link), recursive = FALSE)
sel <- map_lgl(links, ~ .$rel == rel)
sel <- map_lgl(links, \(x) x$rel == rel)
if (sum(sel) != 1L) {
return()
}
Expand Down
2 changes: 1 addition & 1 deletion R/resp-status.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' `req |> req_options(followlocation = FALSE)`.
#' * 4xx client and 5xx server errors are automatically turned into R errors.
#' You can stop them from being turned into R errors with [req_error()],
#' e.g. `req |> req_error(is_error = ~ FALSE)`.
#' e.g. `req |> req_error(is_error = \(resp) FALSE)`.
#'
#' @return
#' * `resp_status()` returns a scalar integer
Expand Down
3 changes: 0 additions & 3 deletions cleanup

This file was deleted.

16 changes: 0 additions & 16 deletions configure

This file was deleted.

3 changes: 0 additions & 3 deletions configure.win

This file was deleted.

2 changes: 1 addition & 1 deletion man/resp_status.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 31 additions & 31 deletions tests/testthat/_snaps/curl.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,81 +38,81 @@
Code
curl_translate("curl http://x.com")
Output
request("http://x.com/") |>
request("http://x.com/") |>
req_perform()
Code
curl_translate("curl http://x.com -X DELETE")
Output
request("http://x.com/") |>
req_method("DELETE") |>
request("http://x.com/") |>
req_method("DELETE") |>
req_perform()
Code
curl_translate("curl http://x.com -H A:1")
Output
request("http://x.com/") |>
request("http://x.com/") |>
req_headers(
A = "1",
) |>
) |>
req_perform()
Code
curl_translate("curl http://x.com -H 'A B:1'")
Output
request("http://x.com/") |>
request("http://x.com/") |>
req_headers(
`A B` = "1",
) |>
) |>
req_perform()
Code
curl_translate("curl http://x.com -u u:p")
Output
request("http://x.com/") |>
req_auth_basic("u", "p") |>
request("http://x.com/") |>
req_auth_basic("u", "p") |>
req_perform()
Code
curl_translate("curl http://x.com --verbose")
Output
request("http://x.com/") |>
request("http://x.com/") |>
req_perform(verbosity = 1)

# can translate query

Code
curl_translate("curl http://x.com?string=abcde&b=2")
Output
request("http://x.com/") |>
request("http://x.com/") |>
req_url_query(
string = "abcde",
b = "2",
) |>
) |>
req_perform()

# can translate data

Code
curl_translate("curl http://example.com --data abcdef")
Output
request("http://example.com/") |>
req_body_raw("abcdef", "application/x-www-form-urlencoded") |>
request("http://example.com/") |>
req_body_raw("abcdef", "application/x-www-form-urlencoded") |>
req_perform()
Code
curl_translate(
"curl http://example.com --data abcdef -H Content-Type:text/plain")
Output
request("http://example.com/") |>
req_body_raw("abcdef", "text/plain") |>
request("http://example.com/") |>
req_body_raw("abcdef", "text/plain") |>
req_perform()

# can translate ocokies

Code
curl_translate("curl 'http://test' -H 'Cookie: x=1; y=2;z=3'")
Output
request("http://test/") |>
request("http://test/") |>
req_cookies_set(
x = "1",
y = "2",
z = "3",
) |>
) |>
req_perform()

# can translate json
Expand All @@ -121,29 +121,29 @@
curl_translate(
"curl http://example.com --data-raw '{\"a\": 1, \"b\": \"text\"}' -H Content-Type:application/json")
Output
request("http://example.com/") |>
request("http://example.com/") |>
req_body_json(
data = list(a = 1L, b = "text"),
) |>
) |>
req_perform()
Code
curl_translate("curl http://example.com --json '{\"a\": 1, \"b\": \"text\"}'")
Output
request("http://example.com/") |>
request("http://example.com/") |>
req_body_json(
data = list(a = 1L, b = "text"),
) |>
) |>
req_perform()

# content type stays in header if no data

Code
curl_translate("curl http://example.com -H Content-Type:text/plain")
Output
request("http://example.com/") |>
request("http://example.com/") |>
req_headers(
`Content-Type` = "text/plain",
) |>
) |>
req_perform()

# can read from clipboard
Expand All @@ -153,31 +153,31 @@
Message
v Copying to clipboard:
Output
request("http://example.com/") |>
request("http://example.com/") |>
req_headers(
A = "1",
B = "2",
) |>
) |>
req_perform()
Code
writeLines(clipr::read_clip())
Output
request("http://example.com/") |>
request("http://example.com/") |>
req_headers(
A = "1",
B = "2",
) |>
) |>
req_perform()

# encode_string2() produces simple strings

Code
curl_translate(cmd)
Output
request("http://example.com/") |>
req_method("PATCH") |>
request("http://example.com/") |>
req_method("PATCH") |>
req_body_json(
data = list(data = list(x = 1L, y = "a", nested = list(z = list(1L, 2L, 3L)))),
) |>
) |>
req_perform()

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/req-body.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# can't change body type

Code
req %>% req_body_json(list(x = 1))
req_body_json(req, list(x = 1))
Condition
Error in `req_body_json()`:
! Can't change body type from raw to json.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/req-error.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

Code
req <- request_test("/status/404")
req <- req %>% req_error(body = ~ resp_body_json(.x)$error)
req %>% req_perform()
req <- req_error(req, body = function(resp) resp_body_json(resp)$error)
req_perform(req)
Condition
Error in `req_perform()`:
! Failed to parse error body with method defined in `req_error()`.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/req-mock.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# local_mock and with_mock are deprecated

Code
local_mock(~ response(404))
local_mock(function(req) response(404))
Condition
Warning:
`local_mock()` was deprecated in httr2 1.1.0.
i Please use `local_mocked_responses()` instead.
Code
. <- with_mock(NULL, ~ response(404))
. <- with_mock(NULL, function(req) response(404))
Condition
Error:
! `with_mock()` was deprecated in httr2 1.1.0 and is now defunct.
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/req-options.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# validates inputs

Code
request_test() %>% req_timeout("x")
req_timeout(request_test(), "x")
Condition
Error in `req_timeout()`:
! `seconds` must be a number, not the string "x".
Code
request_test() %>% req_timeout(0)
req_timeout(request_test(), 0)
Condition
Error in `req_timeout()`:
! `seconds` must be >1 ms.

# req_proxy gives helpful errors

Code
req %>% req_proxy(port = "abc")
req_proxy(req, port = "abc")
Condition
Error in `req_proxy()`:
! `port` must be a whole number or `NULL`, not the string "abc".
Code
req %>% req_proxy("abc", auth = "bsc")
req_proxy(req, "abc", auth = "bsc")
Condition
Error in `req_proxy()`:
! `auth` must be one of "basic", "digest", "gssnegotiate", "ntlm", "digest_ie", or "any", not "bsc".
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/req-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
# errors are forwarded correctly

Code
req %>% req_url_query(1)
req_url_query(req, 1)
Condition
Error in `url_modify_query()`:
! All components of `...` must be named.
Code
req %>% req_url_query(a = I(1))
req_url_query(req, a = I(1))
Condition
Error in `url_modify_query()`:
! Escaped query value `a` must be a single string, not the number 1.
Code
req %>% req_url_query(a = 1:2)
req_url_query(req, a = 1:2)
Condition
Error in `url_modify_query()`:
! All vector elements of `...` must be length 1.
i Use `.multi` to choose a strategy for handling vectors.
Code
req %>% req_url_query(a = mean)
req_url_query(req, a = mean)
Condition
Error in `url_modify_query()`:
! All elements of `...` must be either an atomic vector or NULL.
Expand Down
Loading