Learn R Programming

vcr (version 1.6.0)

RequestHandler: RequestHandler

Description

Base handler for http requests, deciding whether a request is stubbed, to be ignored, recordable, or unhandled

Arguments

Public fields

request_original

original, before any modification

request

the request, after any modification

vcr_response

holds VcrResponse object

stubbed_response

the stubbed response

cassette

the cassette holder

Methods


Method new()

Create a new RequestHandler object

Usage

RequestHandler$new(request)

Arguments

request

The request from an object of class HttpInteraction

Returns

A new RequestHandler object


Method handle()

Handle the request (request given in $initialize())

Usage

RequestHandler$handle()

Returns

handles a request, outcomes vary


Method clone()

The objects of this class are cloneable with this method.

Usage

RequestHandler$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Private Methods

request_type(request)

Get the request type

externally_stubbed()

just returns FALSE

should_ignore()

should we ignore the request, depends on request ignorer infrastructure that's not working yet

has_response_stub()

Check if there is a matching response stub in the http interaction list

get_stubbed_response()

Check for a response and get it

request_summary(request)

get a request summary

on_externally_stubbed_request(request)

on externally stubbed request do nothing

on_ignored_request(request)

on ignored request, do something

on_recordable_request(request)

on recordable request, record the request

on_unhandled_request(request)

on unhandled request, run UnhandledHTTPRequestError

Examples

Run this code
if (FALSE) {
# record mode: once
vcr_configure(
 dir = tempdir(),
 record = "once"
)

data(crul_request)
crul_request$url$handle <- curl::new_handle()
crul_request
x <- RequestHandler$new(crul_request)
# x$handle()

# record mode: none
vcr_configure(
 dir = tempdir(),
 record = "none"
)
data(crul_request)
crul_request$url$handle <- curl::new_handle()
crul_request
insert_cassette("testing_record_mode_none", record = "none")
#file.path(vcr_c$dir, "testing_record_mode_none.yml")
x <- RequestHandlerCrul$new(crul_request)
# x$handle()
crul_request$url$url <- "https://api.crossref.org/works/10.1039/c8sm90002g/"
crul_request$url$handle <- curl::new_handle()
z <- RequestHandlerCrul$new(crul_request)
# z$handle()
eject_cassette("testing_record_mode_none")
}

Run the code above in your browser using DataLab