Skip to content

Commit

Permalink
Fix has_content. Fixes #91
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Dec 17, 2015
1 parent 9507613 commit b683afb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# httr 1.0.0.9000

* `has_content()` correctly tests for the presence/absence of body content (#91).

* Switch to 'openssl' package for hashing, hmac, signatures, and base64.

* Remove the stringr dependency (#285, @jimhester).
Expand Down
2 changes: 1 addition & 1 deletion R/content.r
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ parsed_content <- function(x, ...) {
#' has_content(POST("http://httpbin.org/post", body = FALSE))
#' has_content(HEAD("http://httpbin.org/headers"))
has_content <- function(x) {
length(x) == 0
length(x$content) > 0
}
18 changes: 18 additions & 0 deletions tests/testthat/test-content.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@ test_that("parse content is null if no body", {
out <- content(HEAD("http://httpbin.org/headers"))
expect_equal(out, NULL)
})


# has_content -------------------------------------------------------------

test_that("POST result with empty body doesn't have content", {
r <- POST("http://httpbin.org/post", body = FALSE)
expect_false(has_content(r))
})

test_that("HEAD requests don't have body", {
r <- HEAD("http://httpbin.org/headers")
expect_false(has_content(r))
})

test_that("regular POST does have content", {
r <- POST("http://httpbin.org/post")
expect_true(has_content(r))
})

0 comments on commit b683afb

Please sign in to comment.