From 27548c6c81efdc13a18596d7880c56d0817b4c79 Mon Sep 17 00:00:00 2001 From: Patrick Miller Date: Mon, 1 Apr 2019 17:32:32 -0500 Subject: [PATCH 1/3] toupper --- R/http-verb.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/http-verb.R b/R/http-verb.R index 5ab4525f..00181346 100644 --- a/R/http-verb.R +++ b/R/http-verb.R @@ -14,13 +14,13 @@ #' ) #' stop_for_status(r) #' content(r) -#' +#' #' VERB("POST", url = "http://httpbin.org/post") #' VERB("POST", url = "http://httpbin.org/post", body = "foobar") VERB <- function(verb, url = NULL, config = list(), ..., body = NULL, encode = c("multipart", "form", "json", "raw"), handle = NULL) { hu <- handle_url(handle, url, ...) - req <- request_build(verb, hu$url, body_config(body, match.arg(encode)), config, ...) + req <- request_build(toupper(verb), hu$url, body_config(body, match.arg(encode)), config, ...) request_perform(req, hu$handle$handle) } From d37b14c4f563a2a20b630e9df9aa4eef4cbb70b5 Mon Sep 17 00:00:00 2001 From: Patrick Miller Date: Mon, 1 Apr 2019 17:53:58 -0500 Subject: [PATCH 2/3] toupper method names and test --- NEWS.md | 2 ++ R/http-verb.R | 4 ++-- R/request.R | 2 +- tests/testthat/test-request.r | 5 +++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index f3e610d6..08d45432 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ * `RETRY()` now throws the correct error message if an error occurs during the request (@austin3dickey, #581). +* `VERB()` and `RETRY()` now automatically uppercase methods (@patr1ckm, #571). + # httr 1.4.0 ## OAuth diff --git a/R/http-verb.R b/R/http-verb.R index 00181346..5ab4525f 100644 --- a/R/http-verb.R +++ b/R/http-verb.R @@ -14,13 +14,13 @@ #' ) #' stop_for_status(r) #' content(r) -#' +#' #' VERB("POST", url = "http://httpbin.org/post") #' VERB("POST", url = "http://httpbin.org/post", body = "foobar") VERB <- function(verb, url = NULL, config = list(), ..., body = NULL, encode = c("multipart", "form", "json", "raw"), handle = NULL) { hu <- handle_url(handle, url, ...) - req <- request_build(toupper(verb), hu$url, body_config(body, match.arg(encode)), config, ...) + req <- request_build(verb, hu$url, body_config(body, match.arg(encode)), config, ...) request_perform(req, hu$handle$handle) } diff --git a/R/request.R b/R/request.R index e169ef3a..025c86e0 100644 --- a/R/request.R +++ b/R/request.R @@ -67,7 +67,7 @@ request_build <- function(method, url, ...) { req <- Reduce(request_combine, extra, init = request()) - req$method <- method + req$method <- toupper(method) req$url <- url req diff --git a/tests/testthat/test-request.r b/tests/testthat/test-request.r index c1a2ea84..f52f818f 100644 --- a/tests/testthat/test-request.r +++ b/tests/testthat/test-request.r @@ -14,6 +14,11 @@ test_that("c.request merges headers", { ) }) +test_that('request_build upper cases verbs', { + expect_equal(request_build('get', 'asdf.com')$method, "GET") + expect_equal(request_build('post', 'asdf.com')$method, "POST") +}) + test_that("non-http methods don't parse headers", { # skip on travis to avoid hammering the FTP server, which doesn't # seem to be able to handle multiple simultaneous requests From 2f5a972c3cb7b619899626c62b0e14ffb4539aa6 Mon Sep 17 00:00:00 2001 From: Patrick Miller Date: Mon, 1 Apr 2019 18:08:54 -0500 Subject: [PATCH 3/3] remove toupper on print --- R/request.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/request.R b/R/request.R index 025c86e0..5f7528d8 100644 --- a/R/request.R +++ b/R/request.R @@ -94,7 +94,7 @@ request_combine <- function(x, y) { print.request <- function(x, ...) { cat("\n") if (!is.null(x$method) && !is.null(x$url)) { - cat(toupper(x$method), " ", x$url, "\n", sep = "") + cat(x$method, " ", x$url, "\n", sep = "") } if (!is.null(x$output)) { cat("Output: ", class(x$output)[[1]], "\n", sep = "")