tests/testthat/test-content-type.R

resp <- source("example.com/html.R")$value

test_that("get_content_type handles valid Content-Types, including omitted", {
  expect_identical(resp$headers[["content-type"]], "text/html; charset=utf-8")
  expect_identical(get_content_type(resp), "text/html")
  resp$headers[["content-type"]] <- "application/json"
  expect_identical(get_content_type(resp), "application/json")
  resp$headers[["content-type"]] <- NULL
  expect_identical(get_content_type(resp), "")
})

Try the httptest package in your browser

Any scripts or data that you put into this service are public.

httptest documentation built on July 9, 2023, 7:45 p.m.