R/expect-request-header.R
expect_request_header.Rd
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.
expect_request_header(
expr,
...,
fixed = FALSE,
ignore.case = FALSE,
perl = FALSE,
useBytes = FALSE
)
Code to evaluate
Named headers to match. Values should either be a string (length-1
character), which will be passed to testthat::expect_match()
, or NULL
to
assert that the named header is not present in the request. To assert that a
header is merely present in the request, without asserting anything about its
contents, provide an empty string (""
). Header names are always
case-insensitive; header values will be matched using the following
parameters:
logical. If TRUE
, pattern
is a string to be
matched as is. Overrides all conflicting arguments.
if FALSE
, the pattern matching is case
sensitive and if TRUE
, case is ignored during matching.
logical. Should Perl-compatible regexps be used?
logical. If TRUE
the matching is done
byte-by-byte rather than character-by-character. See
‘Details’.
The value of expr
if there are no expectation failures
if (FALSE) {
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 = ""
)
}