Skip to contents

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

Usage

Response$new(options = list())

Arguments

options

(list) a list of options

Returns

A new Response object


Method print()

print method for the Response class

Usage

Response$print(x, ...)

Arguments

x

self

...

ignored


Method set_url()

set the url for the response

Usage

Response$set_url(url)

Arguments

url

(character) a url

Returns

nothing returned; sets url


Method get_url()

get the url for the response

Usage

Response$get_url()

Returns

(character) a url


Method set_request_headers()

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


Method get_request_headers()

get the request headers for the response

Usage

Response$get_request_headers()

Returns

(list) request headers, a named list


Method set_response_headers()

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


Method get_respone_headers()

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

Usage

Response$get_body()

Returns

various


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

Usage

Response$get_status()

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

Usage

Response$get_exception()

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) {
(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()
}