HeadersPattern | R Documentation |
headers matcher
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")
pattern
a list
new()
Create a new HeadersPattern
object
HeadersPattern$new(pattern)
pattern
(list) a pattern, as a named list, must be named,
e.g,. list(a = 5, b = 6)
A new HeadersPattern
object
matches()
Match a list of headers against that stored
HeadersPattern$matches(headers)
headers
(list) named list of headers, e.g,. list(a = 5, b = 6)
a boolean
empty_headers()
Are headers empty? tests if null or length==0
HeadersPattern$empty_headers(headers)
headers
named list of headers
a boolean
to_s()
Print pattern for easy human consumption
HeadersPattern$to_s()
a string
clone()
The objects of this class are cloneable with this method.
HeadersPattern$clone(deep = FALSE)
deep
Whether to make a deep clone.
(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"))
headers <- list(
"User-Agent" = "Apple",
"Accept-Encoding" = "gzip, deflate",
"Accept" = "application/json, text/xml, application/xml, */*"
)
(x <- HeadersPattern$new(pattern = headers))
x$to_s()
x$pattern
x$matches(headers)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.