resp_headers() retrieves a list of all headers.
resp_header() retrieves a single header.
resp_header_exists() checks if a header is present.
resp_headers(resp, filter = NULL)
resp_header(resp, header, default = NULL)
resp_header_exists(resp, header)A httr2 response object, created by req_perform().
A regular expression used to filter the header names.
NULL, the default, returns all headers.
Header name (case insensitive)
Default value to use if header doesn't exist.
resp_headers() returns a list.
resp_header() returns a string if the header exists and NULL otherwise.
resp_header_exists() returns TRUE or FALSE.
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: Fri, 19 Sep 2025 15:31:39 GMT
#> access-control-allow-origin: *
#> etag: W/"68cd775b-4ae0"
#> expires: Thu, 09 Oct 2025 20:28:44 GMT
#> cache-control: max-age=600
#> content-encoding: gzip
#> x-proxy-cache: MISS
#> x-github-request-id: 316D:1BAAE4:1BD77BC:1EB4179:68E818A4
#> accept-ranges: bytes
#> date: Thu, 09 Oct 2025 20:19:56 GMT
#> via: 1.1 varnish
#> age: 36
#> x-served-by: cache-cmh1290103-CMH
#> x-cache: HIT
#> x-cache-hits: 4
#> x-timer: S1760041196.141443,VS0,VE1
#> vary: Accept-Encoding
#> x-fastly-request-id: a8735c4ebf1d477f2dec32255e63118240ddb885
#> content-length: 4768
resp |> resp_headers("x-")
#> <httr2_headers>
#> x-proxy-cache: MISS
#> x-github-request-id: 316D:1BAAE4:1BD77BC:1EB4179:68E818A4
#> x-served-by: cache-cmh1290103-CMH
#> x-cache: HIT
#> x-cache-hits: 4
#> x-timer: S1760041196.141443,VS0,VE1
#> x-fastly-request-id: a8735c4ebf1d477f2dec32255e63118240ddb885
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