Skip to content

Commit 3cf26fb

Browse files
authored
Use curl to modify/construct urls (#741)
Note that `req_url_path_append()` now only actually affects the path, not other components of the URL like the query params. Fixes #732
1 parent f52f4b9 commit 3cf26fb

13 files changed

Lines changed: 404 additions & 242 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Depends:
1717
R (>= 4.1)
1818
Imports:
1919
cli (>= 3.0.0),
20-
curl (>= 6.2.1),
20+
curl (>= 6.4.0),
2121
glue,
2222
lifecycle,
2323
magrittr,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# httr2 (development version)
22

3+
* URL construction is now powered by `curl::curl_modify_url()`, and hence now (correctly) escapes the `path` component (#732). This means that `req_url_path()` now can only affect the path component of the URL, not the query params or fragment.
34
* Redacted headers are no longer serialized to disk. This is important since it makes it harder to accidentally leak secrets to files on disk, but comes at a cost: you can longer perform such requests that have been saved and reloaded (#721).
45
* New `req_get_method()` and `req_get_body()` allow you to do some limited prediction of what a request _will_ do when it's performed (#718).
56
* Functions that capture interrutps (like `req_perform_parallel()` and friends) are now easier to escape if they're called inside a loop: you can press Ctrl + C twice to guarantee an exit (#1810).

R/resp-url.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#' @export
1010
#' @examples
1111
#' resp <- request(example_url()) |>
12-
#' req_url_path("/get?hello=world") |>
12+
#' req_url_path("/get") |>
13+
#' req_url_query(hello = "world") |>
1314
#' req_perform()
1415
#'
1516
#' resp |> resp_url()

R/url.R

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ url_parse <- function(url, base_url = NULL) {
2424
check_string(url)
2525
check_string(base_url, allow_null = TRUE)
2626

27-
curl <- curl::curl_parse_url(url, baseurl = base_url, decode = FALSE)
27+
curl <- curl::curl_parse_url(url, baseurl = base_url)
2828

2929
parsed <- list(
3030
scheme = curl$scheme,
@@ -267,44 +267,21 @@ url_build <- function(url) {
267267
stop_input_type(url, "a parsed URL")
268268
}
269269

270-
if (!is.null(url$query)) {
271-
query <- url_query_build(url$query)
270+
if (length(url$query) == 0) {
271+
query <- ""
272272
} else {
273-
query <- NULL
273+
query <- I(url_query_build(url$query))
274274
}
275275

276-
if (is.null(url$username) && is.null(url$password)) {
277-
user_pass <- NULL
278-
} else if (is.null(url$username) && !is.null(url$password)) {
279-
cli::cli_abort("Cannot set url {.arg password} without {.arg username}.")
280-
} else if (!is.null(url$username) && is.null(url$password)) {
281-
user_pass <- paste0(url$username, "@")
282-
} else {
283-
user_pass <- paste0(url$username, ":", url$password, "@")
284-
}
285-
286-
if (!is.null(user_pass) || !is.null(url$hostname) || !is.null(url$port)) {
287-
authority <- paste0(user_pass, url$hostname)
288-
if (!is.null(url$port)) {
289-
authority <- paste0(authority, ":", url$port)
290-
}
291-
} else {
292-
authority <- NULL
293-
}
294-
295-
if (is.null(url$path) || !startsWith(url$path, "/")) {
296-
url$path <- paste0("/", url$path)
297-
}
298-
299-
prefix <- function(prefix, x) if (!is.null(x)) paste0(prefix, x)
300-
paste0(
301-
url$scheme,
302-
if (!is.null(url$scheme)) ":",
303-
if (!is.null(url$scheme) || !is.null(authority)) "//",
304-
authority,
305-
url$path,
306-
prefix("?", query),
307-
prefix("#", url$fragment)
276+
curl::curl_modify_url(
277+
scheme = url$scheme,
278+
host = url$hostname,
279+
user = url$username,
280+
password = url$password,
281+
port = url$port,
282+
path = url$path,
283+
query = query,
284+
fragment = url$fragment
308285
)
309286
}
310287

man/resp_url.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

revdep/README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# Revdeps
22

3-
## Failed to check (3)
3+
## Failed to check (1)
44

5-
|package |version |error |warning |note |
6-
|:----------|:-------|:-----|:-------|:----|
7-
|GeoTox |? | | | |
8-
|insight |? | | | |
9-
|parameters |? | | | |
5+
|package |version |error |warning |note |
6+
|:------------|:-------|:-----|:-------|:----|
7+
|arcgisplaces |0.1.2 |1 | | |
8+
9+
## New problems (6)
10+
11+
|package |version |error |warning |note |
12+
|:-------------|:-------|:------|:-------|:----|
13+
|[atrrr](problems.md#atrrr)|0.1.0 |__+1__ | | |
14+
|[httptest2](problems.md#httptest2)|1.1.0 |__+1__ | | |
15+
|[osmapiR](problems.md#osmapir)|0.2.3 |__+2__ | | |
16+
|[planscorer](problems.md#planscorer)|0.0.2 |__+1__ | | |
17+
|[spanishoddata](problems.md#spanishoddata)|0.2.0 |__+1__ | | |
18+
|[tidyllm](problems.md#tidyllm)|0.3.4 |__+1__ | | |
1019

revdep/cran.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
## revdepcheck results
22

3-
We checked 201 reverse dependencies (200 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
3+
We checked 221 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.
44

5-
* We saw 0 new problems
6-
* We failed to check 2 packages
5+
* We saw 6 new problems
6+
* We failed to check 1 packages
77

88
Issues with CRAN packages are summarised below.
99

10+
### New problems
11+
(This reports the first line of each new failure)
12+
13+
* atrrr
14+
checking tests ... ERROR
15+
16+
* httptest2
17+
checking tests ... ERROR
18+
19+
* osmapiR
20+
checking examples ... ERROR
21+
checking tests ... ERROR
22+
23+
* planscorer
24+
checking tests ... ERROR
25+
26+
* spanishoddata
27+
checking tests ... ERROR
28+
29+
* tidyllm
30+
checking tests ... ERROR
31+
1032
### Failed to check
1133

12-
* insight (NA)
13-
* parameters (NA)
34+
* arcgisplaces (NA)

0 commit comments

Comments
 (0)