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

Add req_perform_open, which makes resp$body the underlying stream #521

Merged
merged 27 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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 NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export(req_oauth_refresh)
export(req_options)
export(req_perform)
export(req_perform_iterative)
export(req_perform_open)
export(req_perform_parallel)
export(req_perform_promise)
export(req_perform_sequential)
Expand Down
33 changes: 33 additions & 0 deletions R/req-perform-stream.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@
resp
}


#' @export
req_perform_open <- function(req, blocking = TRUE) {
jcheng5 marked this conversation as resolved.
Show resolved Hide resolved

check_request(req)

Check warning on line 103 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L103

Added line #L103 was not covered by tests

handle <- req_handle(req)

Check warning on line 105 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L105

Added line #L105 was not covered by tests

stream <- curl::curl(req$url, handle = handle)
open(stream, "rbf", blocking = blocking)

Check warning on line 108 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L107-L108

Added lines #L107 - L108 were not covered by tests

res <- curl::handle_data(handle)
the$last_request <- req

Check warning on line 111 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L110-L111

Added lines #L110 - L111 were not covered by tests

# Return early if there's a problem
resp <- new_response(
method = req_method_get(req),
url = res$url,
status_code = res$status_code,
headers = as_headers(res$headers),
body = NULL,
request = req
)
the$last_repsonse <- resp
if (error_is_error(req, resp)) {
resp$body <- read_con(stream)
handle_resp(req, resp)

Check warning on line 125 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L114-L125

Added lines #L114 - L125 were not covered by tests
} else {
resp$body <- stream
resp

Check warning on line 128 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L127-L128

Added lines #L127 - L128 were not covered by tests
}
}

as_round_function <- function(round = c("byte", "line"),
error_call = caller_env()) {
if (is.function(round)) {
Expand Down
Loading