Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement resp_request() #615

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).
* New `url_modify()` makes it easier to modify an existing url (#464).
* New `req_url_relative()` for constructing relative urls (#449).
* `url_parse()` gains `base_url` argument so you can also use it to parse relative URLs (#449).
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)

Check warning on line 13 in R/resp-request.R

View check run for this annotation

Codecov / codecov/patch

R/resp-request.R#L13

Added line #L13 was not covered by tests

resp$request

Check warning on line 15 in R/resp-request.R

View check run for this annotation

Codecov / codecov/patch

R/resp-request.R#L15

Added line #L15 was not covered by tests
}
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)
})
Loading