custom webmockr http response class
Public fields
url
(character) a url
body
(various) list, character, etc
content
(various) response content/body
request_headers
(list) a named list
response_headers
(list) a named list
options
(character) list
status_code
(integer) an http status code
exception
(character) an exception message
should_timeout
(logical) should the response timeout?
Methods
Method new()
Create a new Response
object
Arguments
options
(list) a list of options
Returns
A new Response
object
print method for the Response
class
Method set_url()
set the url for the response
Returns
nothing returned; sets url
Method get_url()
get the url for the response
Returns
(character) a url
set the request headers for the response
Usage
Response$set_request_headers(headers, capitalize = TRUE)
Arguments
headers
(list) named list
capitalize
(logical) whether to capitalize first letters of
each header; default: TRUE
Returns
nothing returned; sets request headers on the response
get the request headers for the response
Usage
Response$get_request_headers()
Returns
(list) request headers, a named list
set the response headers for the response
Usage
Response$set_response_headers(headers, capitalize = TRUE)
Arguments
headers
(list) named list
capitalize
(logical) whether to capitalize first letters of
each header; default: TRUE
Returns
nothing returned; sets response headers on the response
get the response headers for the response
Usage
Response$get_respone_headers()
Returns
(list) response headers, a named list
Method set_body()
set the body of the response
Usage
Response$set_body(body, disk = FALSE)
Arguments
body
(various types)
disk
(logical) whether its on disk; default: FALSE
Returns
nothing returned; sets body on the response
Method get_body()
get the body of the response
Method set_status()
set the http status of the response
Usage
Response$set_status(status)
Arguments
status
(integer) the http status
Returns
nothing returned; sets the http status of the response
Method get_status()
get the http status of the response
Returns
(integer) the http status
Method set_exception()
set an exception
Usage
Response$set_exception(exception)
Arguments
exception
(character) an exception string
Returns
nothing returned; sets an exception
Method get_exception()
get the exception, if set
Returns
(character) an exception
Method clone()
The objects of this class are cloneable with this method.
Usage
Response$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
if (FALSE) { # \dontrun{
(x <- Response$new())
x$set_url("https://httpbin.org/get")
x
x$set_request_headers(list("Content-Type" = "application/json"))
x
x$request_headers
x$set_response_headers(list("Host" = "httpbin.org"))
x
x$response_headers
x$set_status(404)
x
x$get_status()
x$set_body("hello world")
x
x$get_body()
# raw body
x$set_body(charToRaw("hello world"))
x
x$get_body()
x$set_exception("exception")
x
x$get_exception()
} # }