Generally you should not need to use these functions, instead preferring
use_cassette()
or local_cassette()
Usage
insert_cassette(
name,
dir = NULL,
record = NULL,
match_requests_on = NULL,
allow_playback_repeats = FALSE,
serialize_with = NULL,
preserve_exact_body_bytes = NULL,
re_record_interval = NULL,
clean_outdated_http_interactions = NULL,
warn_on_empty = NULL
)
eject_cassette()
Arguments
- name
The name of the cassette. This is used to name a file on disk, so it must be valid file name.
- dir
The directory where the cassette will be stored. If unspecified, (and hasn't been set in
vcr_configure()
) will usetest_path("_vcr")
.- record
Record mode that dictates how HTTP requests/responses are recorded. Possible values are:
once, the default: Replays recorded interactions, records new ones if no cassette exists, and errors on new requests if cassette exists.
none: Replays recorded interactions, and errors on any new requests. Guarnants that no HTTP requests occur.
new_episodes: Replays recorded interactions and always records new ones, even if similar interactions exist.
all: Never replays recorded interactions, always recording new. Useful for re-recording outdated responses or logging all HTTP requests.
- match_requests_on
Character vector of request matchers used to determine which recorded HTTP interaction to replay. Possible values are:
method
: the HTTP method.uri
: the complete request URI, excluding the port.uri_with_port
: the complete request URI, including the port.host
: the host component of the URI.path
: the path component of the URI.query
: the query component of the URI.body
: the request body.body_json
: the request body, parsed as JSON.header
: all request headers.
If more than one is specified, all components must match in order for the request to match. If not supplied, defaults to
c("method", "uri")
.- allow_playback_repeats
(logical) Whether or not to allow a single HTTP interaction to be played back multiple times. Default:
FALSE
.- serialize_with
(character) Which serializer to use. Valid values are "yaml" (default) and "json". Note that you can have multiple cassettes with the same name as long as they use different serializers; so if you only want one cassette for a given cassette name, make sure to not switch serializers, or clean up files you no longer need.
- preserve_exact_body_bytes
(logical) Force a binary (base64) representation of the request and response bondies? By default, vcr will look at the
Content-Type
header to determine if this is necessary, but if it doesn't work you can setprevsere_exact_body_bytes = TRUE
to force it.- re_record_interval
(integer) How frequently (in seconds) the cassette should be re-recorded. default:
NULL
(not re-recorded)- clean_outdated_http_interactions
(logical) Should outdated interactions be recorded back to file? default:
FALSE
- warn_on_empty
Warn if the cassette is ejected but no interactions have been recorded?
Value
A Cassette, invisibly.
Cassette options
Default values for arguments controlling cassette behavior are
inherited from vcr's global configuration. See vcr_configure()
for a
complete list of options and their default settings. You can override these
options for a specific cassette by changing an argument's value to something
other than NULL
when calling either insert_cassette()
or
use_cassette()
.
Examples
vcr_configure(dir = tempdir())
insert_cassette("hello")
current_cassette()
#> <vcr - Cassette> hello
#> Record method: once
#> Serialize with: yaml
#> Re-record interval (s):
#> Clean outdated interactions?: FALSE
#> allow_playback_repeats: FALSE
#> preserve_exact_body_bytes: FALSE
eject_cassette()
#> Warning: ✖ "hello" cassette ejected without recording any interactions.
#> ℹ Did you use {curl}, `download.file()`, or other unsupported tool?
#> ℹ If you are using crul/httr/httr2, are you sure you made an HTTP request?
current_cassette()
#> NULL