Open krivard opened 1 year ago
Hmm, so when you load a mock response, there was no actual request made, so there is no curl_handle
in the response
object, which I think explains the error message.
Also, in the default case, when you record a mock, the response headers aren't kept, only the response body, so there are no Cache-Control headers in the mock response when it is loaded, so you're always in the reperform path, which leads to the error. You can solve this by recording mocks with simplify = FALSE
, so you'd keep all of the response headers (see https://enpiar.com/r/httptest/reference/capture_requests.html). But then that still may result in unexpected behavior if the cache control headers reference a timestamp, unless you edit it to be far into the future to ensure that the test always hits cache.
What behavior exactly are you trying to test?
Oh apologies; my test case wasn't clear.
I don't need to test the caching/rerequest behavior using with_mock_api (I can manually check that logic with mockery if I really want to); I'm most worried about the dozens of existing tests that worked with httr::request but are failing with httr::rerequest. Ideally with_mock_api would treat httr::rerequest just like httr::request, or in other words, the mocked request from httr::request would be one without cache-control headers, rerequest would do the reperform, but with_mock_api would intercept it so that you'd get another mocked request.
Got it. It sounds like if the function that loaded the mock were to include a curl handle, httr::rerequest()
would not error. And it looks like we have the request handle in the function that loads the mocks (https://github.com/nealrichardson/httptest/blob/main/R/mock-api.R#L42-L56), so we might just be able to poke it in there.
Would you be interested in submitting a PR to add this?
I'm working on adding
Cache-Control
handling to a library I test usinghttptest
, and to my dismay, it seems thatwith_mock_api
doesn't handlehttr::rerequest
calls. Is rerequest support planned any time soon?Example: