Skip to content

This overrides the default user-agent set by httr2 which includes the version numbers of httr2, the curl package, and libcurl.

Usage

req_user_agent(req, string = NULL)

Arguments

req

A request.

string

String to be sent in the User-Agent header. If NULL, will user default.

Value

A modified HTTP request.

Examples

# Default user-agent:
request("http://example.com") %>% req_dry_run()
#> GET / HTTP/1.1
#> Host: example.com
#> User-Agent: httr2/0.2.1.9000 r-curl/4.3.2 libcurl/7.68.0
#> Accept: */*
#> Accept-Encoding: deflate, gzip, br
#> 

request("http://example.com") %>% req_user_agent("MyString") %>% req_dry_run()
#> GET / HTTP/1.1
#> Host: example.com
#> User-Agent: MyString
#> Accept: */*
#> Accept-Encoding: deflate, gzip, br
#> 

# If you're wrapping in an API in a package, it's polite to set the
# user agent to identify your package.
request("http://example.com") %>%
  req_user_agent("MyPackage (http://mypackage.com)") %>%
  req_dry_run()
#> GET / HTTP/1.1
#> Host: example.com
#> User-Agent: MyPackage (http://mypackage.com)
#> Accept: */*
#> Accept-Encoding: deflate, gzip, br
#>