1context("Connections") 2 3h <- new_handle() 4 5test_that("Compression and destroying connection", { 6 con <- curl(httpbin("deflate"), handle = h) 7 expect_equal(jsonlite::fromJSON(readLines(con))$deflate, TRUE) 8 expect_false(isOpen(con)) 9 close(con) #destroy 10 11 expect_equal(jsonlite::fromJSON(rawToChar(curl_fetch_memory(httpbin("deflate"), handle = h)$content))$deflate, TRUE) 12 13 con <- curl(httpbin("gzip"), handle = h) 14 expect_equal(jsonlite::fromJSON(readLines(con))$gzipped, TRUE) 15 expect_false(isOpen(con)) 16 close(con) #destroy 17 18 expect_equal(jsonlite::fromJSON(rawToChar(curl_fetch_memory(httpbin("gzip"), handle = h)$content))$gzipped, TRUE) 19}) 20 21test_that("Connection interface", { 22 # note: jsonlite automatically destroys auto-opened connection 23 con <- curl(httpbin("get?test=blabla"), handle = h) 24 expect_equal(jsonlite::fromJSON(con)$args$test, "blabla") 25 26 # test error 27 con <- curl(httpbin("status/418")) 28 expect_error(readLines(con)) 29 close(con) #destroy 30 31 # test not error 32 con <- curl(httpbin("status/418"), handle = h) 33 open(con, "rf") 34 expect_is(readLines(con), "character") 35 expect_equal(handle_data(h)$status_code, 418L) 36 close(con) #destroy 37}) 38