Add information about nectar and the calling package (if called from a package) to the user agent string.
Usage
req_pkg_user_agent(
req,
pkg_name = get_pkg_name(call),
pkg_url = NULL,
call = rlang::caller_env()
)
Arguments
- req
(
httr2_request
) Ahttr2::request()
object.- pkg_name
(
length-1 character
) The name of the calling package. This will usually be automatically determined based on the source of the call.- pkg_url
(
length-1 character
) A url for information about the calling package (defaultNULL
).- call
(
environment
) The environment from which a function was called, e.g.rlang::caller_env()
(the default). The environment will be mentioned in error messages as the source of the error. This argument is particularly useful for functions that are intended to be called as utilities inside other functions.
Value
A httr2::request()
object.
Examples
req <- httr2::request("https://example.com")
req$options$useragent
#> NULL
req_pkg_user_agent(req)$options$useragent
#> httr2/1.1.0 r-curl/6.1.0 libcurl/8.5.0 nectar/0.0.0.9004 (https://nectar.api2r.org)
req_pkg_user_agent(req, "stbl")$options$useragent
#> httr2/1.1.0 r-curl/6.1.0 libcurl/8.5.0 nectar/0.0.0.9004 (https://nectar.api2r.org) stbl/0.1.1.9000