mock_response_connect <- function(req) { if (req$method != "HEAD") { httr2::response(body = 405) } else { if (req$url != "https://cloud.example.com") { httr2::response(status_code = 404) } else { h <- httr2::req_get_headers(req, redacted = "reveal") if (h$Authorization != "Basic YWJjOjEyMw==") { httr2::response(status_code = 401) } else { httr2::response(status_code = 200) } } } } mock_dir <- function(req) { if (req$method != "PROPFIND") { httr2::response(body = 405) } else { if (req$url == "https://cloud.example.com/test") { httr2::response(status_code = 207, header = list("Content-Type" = "application/xml"), body = charToRaw(' /test/ Wed, 28 Feb 2024 21:30:45 GMT 41 527309756657 "65dfa6056af07" HTTP/1.1 200 OK /test/a.csv Wed, 28 Feb 2024 21:30:45 GMT 26 "433f89eafeada7a93501f5b2d0c05651" text/csv HTTP/1.1 200 OK /test/file.txt Wed, 28 Feb 2024 21:28:32 GMT 15 "ff938d81afc36821bb417c98a8e4f2eb" text/plain HTTP/1.1 200 OK /test/tmp/ Wed, 28 Feb 2024 21:29:42 GMT 0 527309756657 "65dfa5c6d4cbe" HTTP/1.1 200 OK ')) } else if ( req$url == "https://cloud.example.com/file.txt" || req$url == "https://cloud.example.com/" ) { httr2::response(status_code = 207, header = list("Content-Type" = "application/xml"), body = charToRaw(' /file.txt Wed, 28 Feb 2024 21:17:51 GMT 15 "763a11253670561a3f03defbbb2f5921" text/plain HTTP/1.1 200 OK ')) } else { httr2::response(status_code = 404) } } } mock_isdir <- function(req) { if (req$method != "PROPFIND") { httr2::response(status_code = 405) } else { if (req$url == "https://cloud.example.com/test") { httr2::response(status_code = 207, headers = list("Content-Type" = "application/xml"), body = charToRaw(' /test/ HTTP/1.1 200 OK ')) } else if (req$url == "https://cloud.example.com/file.txt") { httr2::response(status_code = 207, headers = list("Content-Type" = "application/xml"), body = charToRaw(' /file.txt HTTP/1.1 200 OK ')) } else { httr2::response(status_code = 404) } } } mock_mkdir <- function(req) { if (req$method == "PROPFIND") { if (req$url == "https://cloud.example.com/new") { httr2::response(status_code = 207, headers = list("Content-Type" = "application/xml"), body = charToRaw(' /test/ HTTP/1.1 200 OK ')) } else { httr2::response(status_code = 207, headers = list("Content-Type" = "application/xml"), body = charToRaw(' /test/ HTTP/1.1 200 OK ')) } } else if (req$method != "MKCOL") { httr2::response(body = 405) } else { if (req$url == "https://cloud.example.com/new") { httr2::response(status_code = 200) } else { httr2::response(status_code = 409) } } } mock_copy <- function(req) { if (req$method != "COPY") { httr2::response(body = 405) } else { if (req$url == "https://cloud.example.com/file.txt") { if (req$headers$Destination == "https://cloud.example.com/newfile.txt") { httr2::response(status_code = 200) } else if (req$headers$Overwrite == "F") { httr2::response(status_code = 409) } else { httr2::response(status_code = 200) } } else { httr2::response(status_code = 404) } } } mock_upload <- function(req) { if (req$method == "MKCOL") { httr2::response(status_code = 200) } else if (req$method == "PUT") { if (req$url == "https://cloud.example.com/missing") { httr2::response(status_code = 404) } else { httr2::response(status_code = 200) } } else if (req$method == "PROPFIND") { if (req$url == "https://cloud.example.com/test") { httr2::response(status_code = 207, header = list("Content-Type" = "application/xml"), body = charToRaw(' /test/ HTTP/1.1 200 OK ')) } else if (req$url == "https://cloud.example.com/file.txt") { httr2::response(status_code = 207, header = list("Content-Type" = "application/xml"), body = charToRaw(' /file.txt HTTP/1.1 200 OK ')) } else { httr2::response(status_code = 404) } }else { httr2::response(status_code = 405) } } mock_move <- function(req) { if (req$method != "MOVE") { httr2::response(body = 405) } else { if (req$url == "https://cloud.example.com/file.txt") { if (req$headers$Destination == "https://cloud.example.com/newfile.txt") { httr2::response(status_code = 200) } else if (req$headers$Overwrite == "F") { httr2::response(status_code = 409) } else { httr2::response(status_code = 200) } } else { httr2::response(status_code = 404) } } } mock_delete <- function(req) { if (req$method != "DELETE") { httr2::response(body = 405) } else { if (req$url != "https://cloud.example.com/deleteme") { httr2::response(status_code = 404) } else { httr2::response(status_code = 200) } } }