Wikipedia provides a useful list of common http headers: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields.

add_headers(..., .headers = character())

Arguments

...

named header values. To stop an existing header from being set, pass an empty string: "".

.headers

a named character vector

See also

accept() and content_type() for convenience functions for setting accept and content-type headers.

Other config: authenticate(), config(), set_cookies(), timeout(), use_proxy(), user_agent(), verbose()

Examples

add_headers(a = 1, b = 2)
#> <request> #> Headers: #> * a: 1 #> * b: 2
add_headers(.headers = c(a = "1", b = "2"))
#> <request> #> Headers: #> * a: 1 #> * b: 2
GET("http://httpbin.org/headers")
#> Response [http://httpbin.org/headers] #> Date: 2021-03-29 17:14 #> Status: 200 #> Content-Type: application/json #> Size: 289 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.2.9000", #> "X-Amzn-Trace-Id": "Root=1-60620b02-3407c4f710700e3c37864f86" #> } #> }
# Add arbitrary headers GET( "http://httpbin.org/headers", add_headers(version = version$version.string) )
#> Response [http://httpbin.org/headers] #> Date: 2021-03-29 17:14 #> Status: 200 #> Content-Type: application/json #> Size: 337 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.2.9000", #> "Version": "R version 4.0.4 (2021-02-15)", #> "X-Amzn-Trace-Id": "Root=1-60620b02-2acfb4656b329c3a4372bd45" #> } #> }
# Override default headers with empty strings GET("http://httpbin.org/headers", add_headers(Accept = ""))
#> Response [http://httpbin.org/headers] #> Date: 2021-03-29 17:14 #> Status: 200 #> Content-Type: application/json #> Size: 222 B #> { #> "headers": { #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.2.9000", #> "X-Amzn-Trace-Id": "Root=1-60620b02-3d78fe427c2c3e164d7242db" #> } #> }