Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

* The default value of `failure` argument in `parse_http_date()` is set to `structure(NA_real_, class = "Date")` so that the reponse with a "failure" date can be printed out correctly. (@shrektan, #544)

* `POST()` now uses 22 digits of precision for `body` list elements by default
(@jmwerner, #490)

* No longer parse non-http(s) headers (@billdenney, #537). This makes it
possible to use httr with protocols other than http, although this is not
advised, and you're own your own.
Expand Down
3 changes: 2 additions & 1 deletion R/body.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ body_config <- function(body = NULL,
} else if (encode == "form") {
body_raw(compose_query(body), "application/x-www-form-urlencoded")
} else if (encode == "json") {
body_raw(jsonlite::toJSON(body, auto_unbox = TRUE), "application/json")
body_raw(jsonlite::toJSON(body, auto_unbox = TRUE, digits = 22),
"application/json")
} else if (encode == "multipart") {
if (!all(has_name(body)))
stop("All components of body must be named", call. = FALSE)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-body.r
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ test_that("named list matches form results (encode = 'json')", {
expect_equal(out$json$b[[1]], 2)
})

test_that("decimal precision is preserved (encode = 'json')", {
out <- round_trip(body = list(a = 0.8675309867530986753098675309),
encode = "json")
expect_equal(out$data, "{\"a\":0.867530986753099}")
})

test_that("can do own encoding", {
out <- round_trip(body = '{"a":1,"b":2}', content_type_json(), encode = "raw")
expect_equal(out$json, list(a = 1, b = 2))
Expand Down