-
Notifications
You must be signed in to change notification settings - Fork 82
Closed
Description
👋 Thanks for your continued work on this. Love the "lazy" nature of httr2 v httr
When httr2 is passed a collapsed string of query parameters it automatically escapes then which seems sensible:
library(httr2)
req <- request("http://example.com")
# Change url components
two_queries <- c("one", "two")
collapsed_query <- paste0(two_queries, collapse = ",")
## automatically converts , to %2
(req <- req %>%
req_url_query(q = collapsed_query))
#> <httr2_request>
#> GET http://example.com?q=one%2Ctwo
#> Body: emptyIn {httr} there was, however, the option of unescaping that using I:
library(httr)
r <- GET("http://example.com",
query = list(q = I(collapsed_query))
)
## can use I to use as is
r$url
#> [1] "http://example.com/?q=one,two"This does not work in {httr2}. In {httr} this is accomplished via:
https://github.com/r-lib/httr/blob/21ff69f219ad11298854a63b8f753389088cf382/R/url-query.r#L25-L28
So unless I am missing something (which is of course possible!) we are stuck with doing stuff like:
req <- req %>%
req_url_query(q = collapsed_query)
req$url <- curl::curl_unescape(req$url)
req
#> <httr2_request>
#> GET http://example.com?q=one,two
#> Body: emptyWould you be amenable to a PR that added an escape-like function somewhere, probably in httr2:::url_build`?
alistaire47
Metadata
Metadata
Assignees
Labels
No labels