Skip to content

Commit 756505f

Browse files
committed
Seek in uploads
Fixes #741
1 parent 54c0e9f commit 756505f

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ BugReports: https://github.com/r-lib/httr/issues
1515
Depends:
1616
R (>= 3.5)
1717
Imports:
18-
curl (>= 3.0.0),
18+
curl (>= 5.0.2),
1919
jsonlite,
2020
mime,
2121
openssl (>= 0.8),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# httr 1.4.7
22

3+
* Add support for seeking in uploads (#741).
4+
35
* Suppress another use of httpbin.
46

57
* More aggressively skip httpbin using tests.

R/body.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ body_config <- function(body = NULL,
2525
}
2626
bin
2727
},
28+
seekfunction = function(offset, ...) {
29+
if (is.null(con)) {
30+
con <<- file(body$path, "rb")
31+
}
32+
seek(con, where = offset)
33+
},
2834
postfieldsize_large = size
2935
),
3036
content_type(body$type)

tests/testthat/test-upload-file.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
test_that("can upload with redirect", {
2+
skip_on_cran()
3+
4+
str <- paste(letters, collapse = '')
5+
tmp <- tempfile()
6+
writeBin(str, tmp)
7+
8+
resp <- PUT(
9+
"https://hb.cran.dev/redirect-to?url=/put&status_code=307",
10+
body = upload_file(tmp)
11+
)
12+
13+
expect_equal(resp$status_code, 200)
14+
expect_equal(resp$url, "https://hb.cran.dev/put")
15+
json <- content(resp)
16+
expect_equal(json$data, str)
17+
})

0 commit comments

Comments
 (0)