expect_request_header {httptest2} | R Documentation |
Test that an HTTP request is made with a header
Description
This expectation checks that HTTP headers (and potentially header values) are present in a request. It works both in the mock HTTP contexts and on "live" HTTP requests.
Usage
expect_request_header(
expr,
...,
fixed = FALSE,
ignore.case = FALSE,
perl = FALSE,
useBytes = FALSE
)
Arguments
expr |
Code to evaluate |
... |
Named headers to match. Values should either be a string (length-1
character), which will be passed to |
fixed |
logical. If |
ignore.case |
if |
perl |
logical. Should Perl-compatible regexps be used? |
useBytes |
logical. If |
Value
The value of expr
if there are no expectation failures
Examples
library(httr2)
expect_request_header(
request("http://httpbin.org") %>%
req_headers(Accept = "image/png") %>%
req_perform(),
accept = "image/png",
`x-fake-header` = NULL
)
expect_request_header(
request("http://httpbin.org") %>%
req_headers(Accept = "image/png") %>%
req_perform(),
accept = ""
)