1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
---
title: "vcr configuration"
author: "Scott Chamberlain"
date: "`r Sys.Date()`"
output:
html_document:
toc: true
toc_float: true
theme: readable
vignette: >
%\VignetteIndexEntry{2. vcr configuration}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r echo=FALSE}
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
warning = FALSE,
message = FALSE,
eval = FALSE
)
```
vcr configuration
=================
`vcr` configuration
```{r}
library("vcr")
```
## Get configuration
Use `vcr_configuration()` to get the current configuration.
```{r}
vcr_configuration()
```
You can also get the default configuration variables via `vcr_config_defaults()`
```{r}
vcr_config_defaults()
```
These defaults are set when you load `vcr` - you can override any of them as described below.
## Set configuration variables
Use `vcr_configure()` to set configuration variables.
For example, set a single variable:
```{r}
vcr_configure(
dir = "foobar/vcr_cassettes"
)
```
Or many at once:
```{r}
vcr_configure(
dir = "foobar/vcr_cassettes",
record = "all"
)
```
## Re-set to defaults
```{r}
vcr_configure_reset()
```
## Details on some of the config options
### dir
Directory where cassettes are stored
```{r}
vcr_configure(dir = "new/path")
```
### record
The record mode
One of: 'all', 'none', 'new_episodes', 'once'. See `?recording` for info on the options
```{r}
vcr_configure(record = "new_episodes")
```
### match_requests_on
Customize how `vcr` matches requests
```{r}
vcr_configure(match_requests_on = c('query', 'headers'))
```
### allow_unused_http_interactions
Allow HTTP connections when no cassette
Default is `TRUE`, and thus does not error when http interactions are unused. You
can set to `FALSE` in which case vcr errors when a cassette is ejected and
not all http interactions have been used.
```{r}
vcr_configure(allow_unused_http_interactions = FALSE)
```
### serialize_with
Which serializer to use. Right now only option is "yaml"
```{r}
vcr_configure(serialize_with = "yaml")
```
### persist_with
Which persister to use. Right now only option is "FileSystem"
```{r}
vcr_configure(persist_with = "FileSystem")
```
### ignore_hosts
Specify particular hosts to ignore. By ignore, we mean that
real HTTP requests to the ignored host will be allowed to occur, while
all others will not.
```{r}
vcr_configure(ignore_hosts = "google.com")
```
### ignore_localhost
Ignore all localhost requests
```{r}
vcr_configure(ignore_localhost = TRUE)
```
### ignore_request
Ignore any request for which function `x` is true
```{r}
vcr_configure(ignore_request = function(x) x == 5)
```
### uri_parse
Which uri parser to use
By default we use `crul::url_parse`, but you can use a different one. Remember
to pass in the function quoted, and namespaced.
```{r}
vcr_configure(uri_parser = "urltools::url_parse")
```
### preserve_exact_body_bytes
Some HTTP servers are not well-behaved and respond with invalid data. Set
`preserve_exact_body_bytes` to `TRUE` to base64 encode the result body in
order to preserve the bytes exactly as-is. `vcr` does not do this by
default, since base64-encoding the string removes the human readability
of the cassette.
```{r}
vcr_configure(preserve_exact_body_bytes = TRUE)
```
### filter_sensitive_data
A named list of values to replace. Sometimes your package or script is
working with sensitive tokens/keys, which you do not want to accidentally
share with the world.
Before recording (writing to a cassette) we do the replacement and then when
reading from the cassette we do the reverse replacement to get back
to the real data.
```{r}
vcr_configure(
filter_sensitive_data = list("<some_api_key>" = Sys.getenv('MY_API_KEY'))
)
```
Before recording to disk, the env var `MY_API_KEY` is retrieved from your machine,
and we find instances of it, and replace with `<some_api_key>`. When replaying
to create the HTTP response object we put the real value of the env var
back in place.
## More documentation
Check out the [http testing book](https://ropensci.github.io/http-testing-book/) for a lot more documentation on `vcr`, `webmockr`, and `crul`
|