Skip to content

Commit

Permalink
fix #52 put query arg back into head in HttpClient - add a test for i…
Browse files Browse the repository at this point in the history
…t, bump dev ver
  • Loading branch information
sckott committed Jan 19, 2018
1 parent 757437d commit 2d35def
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: A simple HTTP client, with tools for making HTTP requests,
The package name is a play on curl, the widely used command line tool
for HTTP, and this package is built on top of the R package 'curl', an
interface to 'libcurl' (<https://curl.haxx.se/libcurl>).
Version: 0.4.2.9211
Version: 0.4.2.9611
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"),
Expand Down
8 changes: 4 additions & 4 deletions R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' \item{`delete(path, query, body, disk, stream, ...)`}{
#' Make a DELETE request
#' }
#' \item{`head(path, ...)`}{
#' \item{`head(path, query, ...)`}{
#' Make a HEAD request
#' }
#' }
Expand All @@ -30,7 +30,7 @@
#' @details Possible parameters (not all are allowed in each HTTP verb):
#' \itemize{
#' \item path - URL path, appended to the base URL
#' \item query - query terms, as a list
#' \item query - query terms, as a named list
#' \item body - body as an R list
#' \item encode - one of form, multipart, json, or raw
#' \item disk - a path to write to. if NULL (default), memory used.
Expand Down Expand Up @@ -204,9 +204,9 @@ HttpClient <- R6::R6Class(
private$make_request(rr)
},

head = function(path = NULL, ...) {
head = function(path = NULL, query = list(), ...) {
curl_opts_check(...)
url <- private$make_url(self$url, self$handle, path, NULL)
url <- private$make_url(self$url, self$handle, path, query)
opts <- list(customrequest = "HEAD", nobody = TRUE)
rr <- list(
url = url,
Expand Down
4 changes: 2 additions & 2 deletions man/HttpClient.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/testthat/test-head.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ test_that("head request works", {
# content is empty
expect_equal(aa$content, raw(0))
})


test_that("head - query passed to head doesn't fail", {
skip_on_cran()

cli <- HttpClient$new(url = "https://www.google.com")
aa <- cli$head(query = list(foo = "bar"))

expect_is(aa, "HttpResponse")
expect_is(aa$handle, 'curl_handle')
expect_is(aa$content, "raw")
expect_is(aa$method, "character")
expect_equal(aa$method, "head")
expect_is(aa$parse, "function")
expect_true(aa$success())
expect_match(aa$request$url$url, "foo")
expect_match(aa$request$url$url, "bar")

# content is empty
expect_equal(aa$content, raw(0))
})

0 comments on commit 2d35def

Please sign in to comment.