Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add PUT http method

  • Loading branch information...
commit 1757aa7b913a2ee42dcd5b9650112690fc3325c5 1 parent b27539f
Hadley Wickham authored
Showing with 73 additions and 7 deletions.
  1. +1 −0  NAMESPACE
  2. +11 −7 R/http-put.r
  3. +21 −0 R/request.r
  4. +40 −0 man/PUT.Rd
1  NAMESPACE
View
@@ -9,6 +9,7 @@ export(HEAD)
export(new_bin)
export(parse_url)
export(POST)
+export(PUT)
export(set_config)
export(set_cookies)
export(timeout)
18 R/http-put.r
View
@@ -1,8 +1,12 @@
-PUT <- function(url, content, ...) {
- url <- modify_url(url, ...)
- getURLContent(url,
- customrequest = "PUT",
- postfields = content,
- postfieldsize = str_length(content)
- )
+#' Send PUT to request server.
+#'
+#' @inheritParams GET
+#' @param content Content, if any, to send to server.
+#' @export
+#' @examples
+#' b <- new_bin()
+#' PUT(b)
+PUT <- function(url = NULL, config = list(), content = NULL, ..., handle = NULL) {
+ hu <- handle_url(handle, url, ...)
+ make_request("PUT", hu$handle, hu$url, content = content, config = config)
}
21 R/request.r
View
@@ -11,6 +11,7 @@ make_request <- function(action, handle, url, content, body, config = list()) {
content <- switch(action,
GET = getURL(url, curl = handle$handle, .opts = opts),
POST = post_request(handle, url, body = body, opts = opts),
+ PUT = put_request(handle, url, content = content, opts = opts),
HEAD = head_request(handle, url, opts = opts),
DELETE = delete_request(handle, url, opts = opts),
stop("Unknown action type")
@@ -56,6 +57,26 @@ delete_request <- function(handle, url, opts) {
NULL
}
+put_request <- function(handle, url, content, opts) {
+ opts$url <- url
+ opts$customrequest <- "PUT"
+
+ if (is.null(content)) {
+ opts$nobody <- 1L
+ } else {
+ if (is.character(content)) {
+ content <- charToRaw(paste(content, collapse = "\n"))
+ }
+ opts$readfunction <- content
+ opts$upload <- TRUE
+ opts$infilesize <- length(content)
+ }
+
+ curlPerform(curl = handle$handle, .opts = opts)
+ reset(handle$handle)
+ NULL
+}
+
post_request <- function (handle, url, body = list(), opts = list(), style = "POST", encoding = integer()) {
stopifnot(is.handle(handle))
40 man/PUT.Rd
View
@@ -0,0 +1,40 @@
+\name{PUT}
+\alias{PUT}
+\title{Send PUT to request server.}
+\usage{
+ PUT(url = NULL, config = list(), content = NULL, ...,
+ handle = NULL)
+}
+\arguments{
+ \item{content}{Content, if any, to send to server.}
+
+ \item{url}{the url of the page to retrieve}
+
+ \item{config}{Additional configuration settings such as
+ http authentication (\code{\link{authenticate}}),
+ additional headers (\code{\link{add_headers}}), cookies
+ (\code{\link{set_cookies}}) etc. See
+ \code{\link{config}} for full details and list of
+ helpers.}
+
+ \item{...}{Further parameters, such as \code{query},
+ \code{path}, etc, passed on to \code{\link{modify_url}}.
+ These parameters must be named.}
+
+ \item{handle}{The handle to use with this request. If not
+ supplied, will be retrieved and reused from the
+ \code{\link{handle_pool}} based on the scheme, hostname
+ and port of the url. By default \pkg{httr} requests to
+ the same scheme/host/port combo. This substantially
+ reduces connection time, and ensures that cookies are
+ maintained over multiple requests to the same host. See
+ \code{\link{handle_pool}} for more details.}
+}
+\description{
+ Send PUT to request server.
+}
+\examples{
+b <- new_bin()
+PUT(b)
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.