resp_headers()retrieves a list of all headers.resp_header()retrieves a single header.resp_header_exists()checks if a header is present.
Usage
resp_headers(resp, filter = NULL)
resp_header(resp, header, default = NULL)
resp_header_exists(resp, header)Arguments
- resp
A httr2 response object, created by
req_perform().- filter
A regular expression used to filter the header names.
NULL, the default, returns all headers.- header
Header name (case insensitive)
- default
Default value to use if header doesn't exist.
Value
resp_headers()returns a list.resp_header()returns a string if the header exists andNULLotherwise.resp_header_exists()returnsTRUEorFALSE.
Examples
resp <- request("https://httr2.r-lib.org") |> req_perform()
resp |> resp_headers()
#> <httr2_headers>
#> server: GitHub.com
#> content-type: text/html; charset=utf-8
#> last-modified: Mon, 08 Dec 2025 15:04:45 GMT
#> access-control-allow-origin: *
#> etag: W/"6936e90d-4b79"
#> expires: Fri, 19 Dec 2025 15:48:57 GMT
#> cache-control: max-age=600
#> content-encoding: gzip
#> x-proxy-cache: MISS
#> x-github-request-id: 9F95:210810:C6B2E9:D8F062:6945718E
#> accept-ranges: bytes
#> date: Fri, 19 Dec 2025 15:39:13 GMT
#> via: 1.1 varnish
#> age: 16
#> x-served-by: cache-cmh1290079-CMH
#> x-cache: HIT
#> x-cache-hits: 4
#> x-timer: S1766158753.424670,VS0,VE0
#> vary: Accept-Encoding
#> x-fastly-request-id: 3c8fe25a8218bc65c9d67692d384cd445a1b19e0
#> content-length: 4833
resp |> resp_headers("x-")
#> <httr2_headers>
#> x-proxy-cache: MISS
#> x-github-request-id: 9F95:210810:C6B2E9:D8F062:6945718E
#> x-served-by: cache-cmh1290079-CMH
#> x-cache: HIT
#> x-cache-hits: 4
#> x-timer: S1766158753.424670,VS0,VE0
#> x-fastly-request-id: 3c8fe25a8218bc65c9d67692d384cd445a1b19e0
resp |> resp_header_exists("server")
#> [1] TRUE
resp |> resp_header("server")
#> [1] "GitHub.com"
# Headers are case insensitive
resp |> resp_header("SERVER")
#> [1] "GitHub.com"
# Returns NULL if header doesn't exist
resp |> resp_header("this-header-doesnt-exist")
#> NULL
