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: Thu, 24 Jul 2025 14:49:24 GMT
#> access-control-allow-origin: *
#> etag: W/"688247f4-4ae0"
#> expires: Tue, 29 Jul 2025 17:48:48 GMT
#> cache-control: max-age=600
#> content-encoding: gzip
#> x-proxy-cache: MISS
#> x-github-request-id: 08C2:2C9EE1:1FC6674:220D099:68890727
#> accept-ranges: bytes
#> date: Tue, 29 Jul 2025 19:05:16 GMT
#> via: 1.1 varnish
#> age: 19
#> x-served-by: cache-cmh1290081-CMH
#> x-cache: HIT
#> x-cache-hits: 4
#> x-timer: S1753815916.030167,VS0,VE0
#> vary: Accept-Encoding
#> x-fastly-request-id: 4cd675f10f6b108d604ade8e00de108d49575950
#> content-length: 4768
resp |> resp_headers("x-")
#> <httr2_headers>
#> x-proxy-cache: MISS
#> x-github-request-id: 08C2:2C9EE1:1FC6674:220D099:68890727
#> x-served-by: cache-cmh1290081-CMH
#> x-cache: HIT
#> x-cache-hits: 4
#> x-timer: S1753815916.030167,VS0,VE0
#> x-fastly-request-id: 4cd675f10f6b108d604ade8e00de108d49575950
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