Skip to content

Commit

Permalink
fix #124 fixed httr reading from cached response
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Dec 3, 2019
1 parent ff284bd commit 9820cee
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: Record test suite 'HTTP' requests and replays them during
real 'HTTP' responses on disk in 'cassettes'. Subsequent 'HTTP' requests
matching any previous requests in the same 'cassette' use a cached
'HTTP' response.
Version: 0.3.2.9531
Version: 0.3.2.9532
Authors@R: c(person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "sckott@protonmail.com",
comment = c(ORCID="0000-0003-1444-9135")))
Expand Down
1 change: 1 addition & 0 deletions R/request_handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ RequestHandler <- R6::R6Class(
# get stubbed response
get_stubbed_response = function(request) {
self$stubbed_response <- http_interactions()$response_for(request)
scotts_env$stubbed_response_from_request_handler <- self$stubbed_response
self$stubbed_response
},

Expand Down
9 changes: 0 additions & 9 deletions R/serialize_to_crul.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ serialize_to_crul <- function(request, response) {
# response
resp <- webmockr::Response$new()
resp$set_url(request$uri)
# disk <- "disk" %in% names(response)
# response_body <- if (response$disk) {
# response$disk
# } else {
# if ("string" %in% names(response$body))
# response$body$string
# else
# response$body
# }
bod <- response$body
resp$set_body(if ("string" %in% names(bod)) bod$string else bod,
response$disk %||% FALSE)
Expand Down
3 changes: 1 addition & 2 deletions R/serialize_to_httr.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ serialize_to_httr <- function(request, response) {
resp <- webmockr::Response$new()
resp$set_url(request$uri)
bod <- response$body
disk <- "disk" %in% names(response)
response_body <- if ("file" %in% names(bod)) {
structure(bod$file, class = "path")
} else {
if ("string" %in% names(bod)) bod$string else bod
}
resp$set_body(response_body, disk %||% FALSE)
resp$set_body(response_body, response$disk %||% FALSE)
# resp$set_body(if ("string" %in% names(bod)) bod$string else bod)
resp$set_request_headers(request$headers, capitalize = FALSE)
resp$set_response_headers(response$headers, capitalize = FALSE)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-httr.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ test_that("httr use_cassette works", {
expect_is(x, "response")
expect_equal(x$status_code, 404)
expect_equal(x$url, "https://httpbin.org/404")
expect_output(print(x), "Not Found")
expect_output(print(x), "HTML PUBLIC")

# response body
str <- yaml::yaml.load_file(out$manfile)$http_interactions
Expand Down

0 comments on commit 9820cee

Please sign in to comment.