Skip to content

Commit 5237e77

Browse files
authored
Only close if connection returns fewer bytes than requested (#525)
Fixes #524
1 parent 8c8abd1 commit 5237e77

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# httr2 (development version)
22

3+
* `req_body_file()` now works with files >64kb once more (#524).
34
* New `req_perform_connection()` for working with streaming data. Unlike `req_perform_stream()` which uses callbacks, `req_perform_connection()` returns a regular response object with a connection as the body. It's paired with `resp_stream_bytes()`, `resp_stream_lines()`, and `resp_stream_sse()` that allows you to stream chunks as you want them. Unlike `req_perform_stream()` it supports `req_retry()` (with @jcheng5, #519).
45

56
# httr2 1.0.3

R/req-body.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ req_body_apply <- function(req) {
213213
return(raw())
214214
}
215215
out <- readBin(con, "raw", nbytes)
216-
if (length(out) <= nbytes) {
216+
if (length(out) < nbytes) {
217217
close(con)
218218
done <<- TRUE
219219
con <<- NULL

tests/testthat/test-req-body.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
test_that("can send file", {
2-
skip_on_os("windows") # fails due to line ending difference
3-
4-
path <- tempfile()
5-
writeLines("this is a test", path)
2+
path <- withr::local_tempfile()
3+
# curl requests in 64kb chunks so this will hopefully illustrate
4+
# any subtle problems
5+
x <- strrep("x", 128 * 1024)
6+
writeChar(x, path, nchar(x))
67

78
resp <- request_test("/post") %>%
89
req_body_file(path, type = "text/plain") %>%
910
req_perform()
1011

1112
json <- resp_body_json(resp)
1213
expect_equal(json$headers$`Content-Type`, "text/plain")
13-
expect_equal(json$data, "this is a test\n")
14+
expect_equal(json$data, x)
1415
})
1516

1617
test_that("can send file with redirect", {

0 commit comments

Comments
 (0)