From 1866f7a2a3789cf365bf7cd476544877e1fffbea Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Thu, 25 Apr 2024 09:23:38 -0400 Subject: [PATCH 1/2] Remove request from saved responses --- R/capture-requests.R | 1 + tests/testthat/test-capture-requests.R | 1 + 2 files changed, 2 insertions(+) diff --git a/R/capture-requests.R b/R/capture-requests.R index 3e7f7dc..3bcff2a 100644 --- a/R/capture-requests.R +++ b/R/capture-requests.R @@ -166,6 +166,7 @@ save_response <- function(response, file, simplify = TRUE) { } # Needed for httr2 1.0.0 response$cache <- quote(new.env(parent = emptyenv())) + response$request <- NULL f <- file(dst_file, "wb", encoding = "UTF-8") on.exit(close(f)) diff --git a/tests/testthat/test-capture-requests.R b/tests/testthat/test-capture-requests.R index fb0eead..5507ce5 100644 --- a/tests/testthat/test-capture-requests.R +++ b/tests/testthat/test-capture-requests.R @@ -53,6 +53,7 @@ test_that("We can record a series of requests (a few ways)", { teapot <- source(file.path(d, httpbin_mock_url, "status", "418.R"))$value expect_s3_class(teapot, "httr2_response") expect_identical(resp_status(teapot), 418L) + expect_false("request" %in% names(teapot)) # Make sure that our .html file has HTML expect_true(any(grepl( "", From 2b8159df1ca36ec164778e55f81bb63026de68aa Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Thu, 25 Apr 2024 09:23:59 -0400 Subject: [PATCH 2/2] Bump dev version and add news --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ba46777..1c17ca2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Testing and documenting code that communicates with remote servers test fixtures. The ability to save responses and load them offline also enables writing vignettes and other dynamic documents that can be distributed without access to a live server. -Version: 1.0.0 +Version: 1.0.0.9000 Authors@R: c( person("Neal", "Richardson", role=c("aut", "cre"), email="neal.p.richardson@gmail.com", comment=c(ORCID="0009-0002-7992-3520")), person("Jonathan", "Keane", role="ctb", email="jkeane@gmail.com"), diff --git a/NEWS.md b/NEWS.md index 8c7192f..878ad31 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# httptest2 1.0.0.9000 + +* `request` is now removed when saving `httr2_response` objects. In earlier versions of `httr2`, requests were not included in responses, but in httr2 1.0.0, [they were added](https://github.com/r-lib/httr2/pull/359) in order to improve error messages. *If you recorded any responses with httr2 >= 1.0 and httptest2 prior to this version, you may have leaked auth secrets: this would happen if your requests included auth information (as in an `Authentication` header), and the response was saved in a .R file, not simplified to .json or other response-body-only formats. Please inspect your recorded responses and invalidate any tokens that were exposed.* + # httptest2 1.0.0 * `capture_requests()` can be used without loading `library(httptest2)` (#22, @kforner)