Merge branch 'patch-1' of https://github.com/mr-c/arvados into mr-c-patch-1
[arvados.git] / sdk / R / R / HttpRequest.R
index 2a5c4fa556817f6ae650674ddeced7ab7026cf7a..07defca90f4c99e8be9f8a73f7412f398ab1a701 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
 source("./R/util.R")
 
 HttpRequest <- R6::R6Class(
@@ -9,10 +13,10 @@ HttpRequest <- R6::R6Class(
         validContentTypes = NULL,
         validVerbs = NULL,
 
-        initialize = function() 
+        initialize = function()
         {
             self$validContentTypes <- c("text", "raw")
-            self$validVerbs <- c("GET", "POST", "PUT", "DELETE", "PROPFIND", "MOVE")
+            self$validVerbs <- c("GET", "POST", "PUT", "DELETE", "PROPFIND", "MOVE", "COPY")
         },
 
         exec = function(verb, url, headers = NULL, body = NULL, queryParams = NULL,
@@ -21,13 +25,16 @@ HttpRequest <- R6::R6Class(
             if(!(verb %in% self$validVerbs))
                 stop("Http verb is not valid.")
 
-            headers  <- httr::add_headers(unlist(headers))
             urlQuery <- self$createQuery(queryParams)
             url      <- paste0(url, urlQuery)
 
+            config <- httr::add_headers(unlist(headers))
+            if(toString(Sys.getenv("ARVADOS_API_HOST_INSECURE") == "TRUE"))
+               config$options = list(ssl_verifypeer = 0L)
+
             # times = 1 regular call + numberOfRetries
             response <- httr::RETRY(verb, url = url, body = body,
-                                    config = headers, times = retryTimes + 1)
+                                    config = config, times = retryTimes + 1)
         },
 
         createQuery = function(queryParams)
@@ -51,6 +58,17 @@ HttpRequest <- R6::R6Class(
             }
 
             return("")
+        },
+
+        getConnection = function(url, headers, openMode)
+        {
+            h <- curl::new_handle()
+            curl::handle_setheaders(h, .list = headers)
+
+            if(toString(Sys.getenv("ARVADOS_API_HOST_INSECURE") == "TRUE"))
+               curl::handle_setopt(h, ssl_verifypeer = 0L)
+
+            conn <- curl::curl(url = url, open = openMode, handle = h)
         }
     ),