httr2 equivalent of httr::set_config ?
https://httr2.r-lib.org/reference/index.html
Is there an equivalent way to set global configurations that will be used by all requests?
I'm specifically looking for a way for an R user to set a proxy configuration that would apply to all requests made in an R session.
There's nothing equivalent, but maybe there should be, just for proxies.
Thanks for confirming! I'll stick with httr for this purpose for now.
How would you see this being implemented here? I would love to help if possible.
I don't know yet; I need to think about it.
Hello, I am glad this issue already exists. I would like to second the motion to add something similar to httr::set_config. I use it a lot in scripts where I work with API wrappers based on httr. However, now I am set to work with a R package API wrapper based on httr2 which at the moment does not provide support to add options to the underlying HTTP request through its API, making it necessary to have some way to globally set the configuration.
And in addition to that: Thank you so, so much for all your amazing work here, Hadley!
Out of interest, what sort of options are you looking to set?
In order to configure my proxy settings I need the following:
- Proxy URL
- Username / password
- Authentication method (e.g., NTLM)
It works totally fine used in req_options or req_proxy, however using the package (restatis in my case) I cannot pass these on to the httr2 pipeline used in a non-exported function (we might add support for that later but it would be great if there was a way to globally set the above settings).
Thanks! Definitely something I plan to add when I'm next working on httr2.
Would also be useful if you want to set up caching.
Since req_throttle() and req_retry() already do this, I wonder if we should have the ability to set options per hostname. That feels like it would be useful in order to add additional options to an arbitrary package, without affecting every single call.
Maybe something like this?
host_config("google.org", \(req) req |> req_set_header("foo"))
host_config("*", \(req) req |> req_proxy_something())
Would then need some kind of host matching algorithm but maybe it's possible to hack something together with regexps that's good enough?
hostname_to_regex <- function(x) {
x <- gsub(".", "\\\\.", x, fixed = TRUE)
x <- gsub("*", ".*", x, fixed = TRUE)
x <- paste0("^", x, "$")
x
}