File: VcrResponse.Rd

package info (click to toggle)
r-cran-vcr 0.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,360 kB
  • sloc: cpp: 15; sh: 13; makefile: 2
file content (310 lines) | stat: -rw-r--r-- 8,879 bytes parent folder | download
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/response_class.R
\name{VcrResponse}
\alias{VcrResponse}
\title{The response of an HTTPInteraction}
\description{
Custom vcr http response object
}
\examples{
\dontrun{
vcr_configure(dir = tempdir())

# basic example of VcrResponse use
url <- "https://google.com"
(cli <- crul::HttpClient$new(url = url))
(res <- cli$get("get", query = list(q = "stuff")))
(x <- VcrResponse$new(res$status_http(), res$response_headers,
   res$parse("UTF-8"), res$response_headers$status))
x$body
x$status
x$headers
x$http_version
x$to_hash()
x$from_hash(x$to_hash())

# update content length header
## example 1
### content-length header present, but no change
url <- "https://fishbase.ropensci.org"
cli <- crul::HttpClient$new(url = url, headers = list(`Accept-Encoding` = '*'))
res <- cli$get("species/34")
x <- VcrResponse$new(res$status_http(), res$response_headers,
   res$parse("UTF-8"), res$response_headers$status)
x$headers$`content-length`
x$update_content_length_header()
x$headers$`content-length`

## example 2
### no content-length header b/c a transfer-encoding header is included
### and no content-length header allowed if transfer-encoding header
### used (via rfc7230)
url <- "https://google.com"
cli <- crul::HttpClient$new(url = url)
res <- cli$get()
x <- VcrResponse$new(res$status_http(), res$response_headers,
   rawToChar(res$content), res$response_headers$status)
x$headers$`content-length` # = NULL
x$update_content_length_header() # no change, b/c header doesn't exist
x$headers$`content-length` # = NULL

## example 3
### content-length header present, and does change
body <- " Hello World "
x <- VcrResponse$new(200, list('content-length'=nchar(body)),
  body, "HTTP/2")
x$headers$`content-length` # = 13
x$body <- gsub("^\\\\s|\\\\s$", "", x$body)
x$headers$`content-length` # = 13
x$update_content_length_header()
x$headers$`content-length` # = 11

# check if body is compressed
url <- "https://fishbase.ropensci.org"
(cli <- crul::HttpClient$new(url = url))
(res <- cli$get("species/3"))
res$response_headers
(x <- VcrResponse$new(res$status_http(), res$response_headers,
   res$parse("UTF-8"), res$response_headers$status))
x$content_encoding()
x$is_compressed()

# with disk
url <- "https://google.com"
(cli <- crul::HttpClient$new(url = url))
f <- tempfile()
(res <- cli$get("get", query = list(q = "stuff"), disk = f))
(x <- VcrResponse$new(res$status_http(), res$response_headers,
   f, res$response_headers$status, disk = TRUE))
}
}
\keyword{internal}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{status}}{the status of the response}

\item{\code{headers}}{the response headers}

\item{\code{body}}{the response body}

\item{\code{http_version}}{the HTTP version}

\item{\code{opts}}{a list}

\item{\code{adapter_metadata}}{Additional metadata used by a specific VCR adapter}

\item{\code{hash}}{a list}

\item{\code{disk}}{a boolean}
}
\if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-new}{\code{VcrResponse$new()}}
\item \href{#method-to_hash}{\code{VcrResponse$to_hash()}}
\item \href{#method-from_hash}{\code{VcrResponse$from_hash()}}
\item \href{#method-update_content_length_header}{\code{VcrResponse$update_content_length_header()}}
\item \href{#method-get_header}{\code{VcrResponse$get_header()}}
\item \href{#method-edit_header}{\code{VcrResponse$edit_header()}}
\item \href{#method-delete_header}{\code{VcrResponse$delete_header()}}
\item \href{#method-content_encoding}{\code{VcrResponse$content_encoding()}}
\item \href{#method-is_compressed}{\code{VcrResponse$is_compressed()}}
\item \href{#method-clone}{\code{VcrResponse$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-new"></a>}}
\if{latex}{\out{\hypertarget{method-new}{}}}
\subsection{Method \code{new()}}{
Create a new VcrResponse object
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$new(
  status,
  headers,
  body,
  http_version,
  opts,
  adapter_metadata = NULL,
  disk
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{status}}{the status of the response}

\item{\code{headers}}{the response headers}

\item{\code{body}}{the response body}

\item{\code{http_version}}{the HTTP version}

\item{\code{opts}}{a list}

\item{\code{adapter_metadata}}{Additional metadata used by a specific VCR adapter}

\item{\code{disk}}{boolean, is body a file on disk}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A new \code{VcrResponse} object
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-to_hash"></a>}}
\if{latex}{\out{\hypertarget{method-to_hash}{}}}
\subsection{Method \code{to_hash()}}{
Create a hash
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$to_hash()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
a list
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-from_hash"></a>}}
\if{latex}{\out{\hypertarget{method-from_hash}{}}}
\subsection{Method \code{from_hash()}}{
Get a hash back to an R list
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$from_hash(hash)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{hash}}{a list}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
an \code{VcrResponse} object
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-update_content_length_header"></a>}}
\if{latex}{\out{\hypertarget{method-update_content_length_header}{}}}
\subsection{Method \code{update_content_length_header()}}{
Updates the Content-Length response header so that
it is accurate for the response body
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$update_content_length_header()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
no return; modifies the content length header
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-get_header"></a>}}
\if{latex}{\out{\hypertarget{method-get_header}{}}}
\subsection{Method \code{get_header()}}{
Get a header by name
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$get_header(key)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{key}}{(character) header name to get}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
the header value (if it exists)
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-edit_header"></a>}}
\if{latex}{\out{\hypertarget{method-edit_header}{}}}
\subsection{Method \code{edit_header()}}{
Edit a header
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$edit_header(key, value = NULL)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{key}}{(character) header name to edit}

\item{\code{value}}{(character) new value to assign}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
no return; modifies the header in place
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-delete_header"></a>}}
\if{latex}{\out{\hypertarget{method-delete_header}{}}}
\subsection{Method \code{delete_header()}}{
Delete a header
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$delete_header(key)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{key}}{(character) header name to delete}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
no return; the header is deleted if it exists
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-content_encoding"></a>}}
\if{latex}{\out{\hypertarget{method-content_encoding}{}}}
\subsection{Method \code{content_encoding()}}{
Get the content-encoding header value
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$content_encoding()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
(character) the content-encoding value
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-is_compressed"></a>}}
\if{latex}{\out{\hypertarget{method-is_compressed}{}}}
\subsection{Method \code{is_compressed()}}{
Checks if the encoding is one of "gzip" or "deflate"
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$is_compressed()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
logical
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-clone"></a>}}
\if{latex}{\out{\hypertarget{method-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{VcrResponse$clone(deep = FALSE)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}