To match previously recorded requests, vcr has to try to match new HTTP requests to a previously recorded one. By default, we match on HTTP method (e.g., GET) and URI (e.g., http://foo.com), following Ruby's VCR gem.

You can customize how we match requests with one or more of the following options, some of which are on by default, some of which can be used together, and some alone.

You can set your own options by tweaking the match_requests_on parameter in use_cassette():

library(vcr)
unlink(file.path(cassette_path(), "foo_bar.yml"))
use_cassette(name = "foo_bar", {
    cli$post("post", body = list(a = 5))
  }, 
  match_requests_on = c('method', 'headers', 'body')
)
unlink(file.path(cassette_path(), "foo_bar.yml"))

Matching

headers

unlink(file.path(cassette_path(), "nothing_new.yml"))
library(crul)
library(vcr)
cli <- crul::HttpClient$new("https://httpbin.org/get", 
  headers = list(foo = "bar"))
use_cassette(name = "nothing_new", {
    one <- cli$get()
  }, 
  match_requests_on = 'headers'
)
cli$headers$foo <- "stuff"
use_cassette(name = "nothing_new", {
    two <- cli$get()
  }, 
  match_requests_on = 'headers'
)
one$request_headers
two$request_headers
unlink(file.path(cassette_path(), "nothing_new.yml"))


ropenscilabs/vcr documentation built on Feb. 5, 2024, 5:58 p.m.