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 httr2 request object.

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/1.0.7 r-curl/6.0.1 libcurl/7.81.0
#> Accept: */*
#> Accept-Encoding: deflate, gzip, br, zstd
#> 

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, zstd
#> 

# 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, zstd
#>