Skip to contents

request and response summary methods

Usage

request_summary(request, request_matchers = "")

response_summary(response)

Arguments

request

a Request object

request_matchers

(character) a vector of matchers. Default: ""

response

a VcrResponse object

Value

character string, of either request or response

Details

By default, method and uri are included in the request summary - if body and/or headers are specified in request_matchers, then they are also included

HTTP status code and response body are included in the response summary. The response body is truncated to a max of 80 characters

In response_summary() we use gsub with useBytes=TRUE to avoid problems sometimes seen with multibyte strings - this shouldn't affect your data/etc. as this is only for printing a summary of the response

Examples

# request
url <- "https://hb.opencpu.org"
body <- list(foo = "bar")
headers <- list(
  `User-Agent` = "r-curl/3.2",
  `Accept-Encoding` = "gzip, deflate",
  Accept = "application/json"
)

(x <- Request$new("POST", url, body, headers))
#> <Request>
#>   Public:
#>     body: foo=bar
#>     clone: function (deep = FALSE) 
#>     disk: NULL
#>     fields: NULL
#>     from_hash: function (hash) 
#>     hash: NULL
#>     headers: list
#>     host: hb.opencpu.org
#>     initialize: function (method, uri, body, headers, opts, disk, fields, output, 
#>     method: post
#>     opts: NULL
#>     output: NULL
#>     path: NA
#>     query: NA
#>     scheme: https
#>     skip_port_stripping: FALSE
#>     to_hash: function () 
#>     uri: https://hb.opencpu.org/
#>   Private:
#>     parsed_uri: function (uri) 
#>     without_standard_port: function (uri) 
request_summary(request = x)
#> [1] "post https://hb.opencpu.org/"
request_summary(request = x, c('method', 'uri'))
#> [1] "post https://hb.opencpu.org/"
request_summary(request = x, c('method', 'uri', 'body'))
#> [1] "post https://hb.opencpu.org/ foo=bar"
request_summary(request = x, c('method', 'uri', 'headers'))
#> [1] "post https://hb.opencpu.org/ r-curl/3.2 gzip, deflate application/json"
request_summary(request = x, c('method', 'uri', 'body', 'headers'))
#> [1] "post https://hb.opencpu.org/ foo=bar r-curl/3.2 gzip, deflate application/json"

# response
status <- list(status_code = 200, message = "OK",
  explanation = "Request fulfilled, document follows")
headers <- list(
  status = "HTTP/1.1 200 OK",
  connection = "keep-alive",
  date = "Tue, 24 Apr 2018 04:46:56 GMT"
)
response_body <- 
"{\"args\": {\"q\": \"stuff\"}, \"headers\": {\"Accept\": \"text/html\"}}\n"
(x <- VcrResponse$new(status, headers,
   response_body, "HTTP/1.1 200 OK"))
#> <VcrResponse> 
response_summary(x)
#> [1] "200 {\"args\": {\"q\": \"stuff\"}, \"headers\": {\"Accept\": \"text/html\"}} "

## with binary body
# path <- "tests/testthat/png_eg.rda"
# load(path)
# (x <- VcrResponse$new(status, headers, png_eg, "HTTP/1.1 200 OK"))
# response_summary(x)