| resp_headers {httr2} | R Documentation |
Extract headers from a response
Description
-
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 |
An HTTP response object, as created by |
filter |
A regular expression used to filter the header names.
|
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()
resp |> resp_headers("x-")
resp |> resp_header_exists("server")
resp |> resp_header("server")
# Headers are case insensitive
resp |> resp_header("SERVER")
# Returns NULL if header doesn't exist
resp |> resp_header("this-header-doesnt-exist")
[Package httr2 version 1.0.2 Index]