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 print()
print method for the Response
class
Method set_request_headers()
set the request headers for the response
Method set_response_headers()
set the response headers for the response
Examples
(x <- Response$new())
#> <webmockr response>
#> url:
#> status: 200
#> headers:
#> request headers:
#> response headers:
#> exception:
#> body length: 0
x$set_url("https://httpbin.org/get")
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 200
#> headers:
#> request headers:
#> response headers:
#> exception:
#> body length: 0
x$set_request_headers(list("Content-Type" = "application/json"))
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 200
#> headers:
#> request headers:
#> Content-Type: application/json
#> response headers:
#> exception:
#> body length: 0
x$request_headers
#> $`Content-Type`
#> [1] "application/json"
#>
x$set_response_headers(list("Host" = "httpbin.org"))
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 200
#> headers:
#> request headers:
#> Content-Type: application/json
#> response headers:
#> Host: httpbin.org
#> exception:
#> body length: 0
x$response_headers
#> $Host
#> [1] "httpbin.org"
#>
x$set_status(404)
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 404
#> headers:
#> request headers:
#> Content-Type: application/json
#> response headers:
#> Host: httpbin.org
#> exception:
#> body length: 0
x$get_status()
#> [1] 404
x$set_body("hello world")
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 404
#> headers:
#> request headers:
#> Content-Type: application/json
#> response headers:
#> Host: httpbin.org
#> exception:
#> body length: 11
x$get_body()
#> [1] 68 65 6c 6c 6f 20 77 6f 72 6c 64
# raw body
x$set_body(charToRaw("hello world"))
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 404
#> headers:
#> request headers:
#> Content-Type: application/json
#> response headers:
#> Host: httpbin.org
#> exception:
#> body length: 11
x$get_body()
#> [1] 68 65 6c 6c 6f 20 77 6f 72 6c 64
x$set_exception("exception")
x
#> <webmockr response>
#> url: https://httpbin.org/get
#> status: 404
#> headers:
#> request headers:
#> Content-Type: application/json
#> response headers:
#> Host: httpbin.org
#> exception: exception
#> body length: 11
x$get_exception()
#> [1] "exception"