Skip to content

Commit

Permalink
Seek in uploads
Browse files Browse the repository at this point in the history
Fixes #741
  • Loading branch information
hadley committed Aug 15, 2023
1 parent 54c0e9f commit 756505f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BugReports: https://github.com/r-lib/httr/issues
Depends:
R (>= 3.5)
Imports:
curl (>= 3.0.0),
curl (>= 5.0.2),
jsonlite,
mime,
openssl (>= 0.8),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# httr 1.4.7

* Add support for seeking in uploads (#741).

* Suppress another use of httpbin.

* More aggressively skip httpbin using tests.
Expand Down
6 changes: 6 additions & 0 deletions R/body.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ body_config <- function(body = NULL,
}
bin
},
seekfunction = function(offset, ...) {
if (is.null(con)) {
con <<- file(body$path, "rb")
}
seek(con, where = offset)
},
postfieldsize_large = size
),
content_type(body$type)
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-upload-file.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("can upload with redirect", {
skip_on_cran()

str <- paste(letters, collapse = '')
tmp <- tempfile()
writeBin(str, tmp)

resp <- PUT(
"https://hb.cran.dev/redirect-to?url=/put&status_code=307",
body = upload_file(tmp)
)

expect_equal(resp$status_code, 200)
expect_equal(resp$url, "https://hb.cran.dev/put")
json <- content(resp)
expect_equal(json$data, str)
})

0 comments on commit 756505f

Please sign in to comment.