Learn R Programming

webmockr (version 0.1.0)

HeadersPattern: HeadersPattern

Description

HeadersPattern

Arguments

pattern
(list) a pattern, as a named list, must be named, e.g,. list(a = 5, b = 6)

Details

Methods
matches(headers)
Match a list of headers against that stored - headers (list) named list of headers, e.g,. list(a = 5, b = 6)

webmockr normalises headers and treats all forms of same headers as equal: i.e the following two sets of headers are equal: list(Header1 = "value1", content_length = 123, X_CuStOm_hEAder = "foo") and list(header1 = "value1", "Content-Length" = 123, "x-cuSTOM-HeAder" = "foo")

Examples

Run this code
(x <- HeadersPattern$new(pattern = list(a = 5)))
x$pattern
x$matches(list(a = 5))

# different cases
(x <- HeadersPattern$new(pattern = list(Header1 = "value1")))
x$pattern
x$matches(list(header1 = "value1"))
x$matches(list(header1 = "value2"))

# different symbols
(x <- HeadersPattern$new(pattern = list(`Hello_World` = "yep")))
x$pattern
x$matches(list(`hello-world` = "yep"))
x$matches(list(`hello-worlds` = "yep"))

Run the code above in your browser using DataLab