expect_header: Test that an HTTP request is made with a header

View source: R/expect-header.R

expect_headerR Documentation

Test that an HTTP request is made with a header

Description

This expectation checks that a HTTP header (and potentially header value) is present in a request. It works by inspecting the request object and raising warnings that are caught by testthat::expect_warning().

Usage

expect_header(..., ignore.case = TRUE)

Arguments

...

Arguments passed to expect_warning

ignore.case

logical: if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching. Default is TRUE; note that this is the opposite of expect_warning but is appropriate here because HTTP header names are case insensitive.

Details

expect_header works both in the mock HTTP contexts and on "live" HTTP requests.

Value

NULL, according to expect_warning.

Examples

library(httr)
with_fake_http({
  expect_header(
    GET("http://example.com", config = add_headers(Accept = "image/png")),
    "Accept: image/png"
  )
})

httptest documentation built on July 9, 2023, 7:45 p.m.