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()
#> $args
#> named list()
#> 
#> $data
#> named list()
#> 
#> $files
#> named list()
#> 
#> $form
#> named list()
#> 
#> $headers
#> $headers$Host
#> [1] "127.0.0.1:32769"
#> 
#> $headers$`User-Agent`
#> [1] "httr2/1.0.2.9000 r-curl/5.2.1 libcurl/7.81.0"
#> 
#> $headers$Accept
#> [1] "*/*"
#> 
#> $headers$`Accept-Encoding`
#> [1] "deflate, gzip, br, zstd"
#> 
#> 
#> $json
#> named list()
#> 
#> $method
#> [1] "get"
#> 
#> $path
#> [1] "/delay/2"
#> 
#> $origin
#> [1] "127.0.0.1"
#> 
#> $url
#> [1] "http://127.0.0.1:32769/delay/2"
#> 
#> GET / HTTP/1.1
#> Host: example.com
#> User-Agent: httr2/1.0.2.9000 r-curl/5.2.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
#>