Skip to content

Commit

Permalink
Implement resp_request() (#615)
Browse files Browse the repository at this point in the history
Fixes #604
  • Loading branch information
hadley authored Jan 6, 2025
1 parent 20d1f7c commit 63b6e14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# httr2 (development version)

* New `resp_request()` aids debugging by returning the request associated with a response (#604).
* `print.request()` now correctly escapes `{}` in headers (#586).
* New `req_headers_redacted()` provides a user-friendlier way to set redacted headers (#561).
* `resp_link_url()` now works if there are multiple `Link` headers (#587).
Expand Down
16 changes: 16 additions & 0 deletions R/resp-request.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Find the request responsible for a response
#'
#' To make debugging easier, httr2 includes the request that was used to
#' generate every response. You can use this function to access it.
#'
#' @inheritParams resp_header
#' @export
#' @examples
#' req <- request_test()
#' resp <- req_perform(req)
#' resp_request(resp)
resp_request <- function(resp) {
check_response(resp)

resp$request
}
5 changes: 5 additions & 0 deletions tests/testthat/test-resp-request.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_that("can extract request", {
req <- request_test()
resp <- req_perform(req)
expect_equal(resp_request(resp), req)
})

0 comments on commit 63b6e14

Please sign in to comment.