inst/tinytest/test-app-cors.R

# Test AuthMiddleware class

app = ex_app("cors")
rq = Request$new(path = "/cors", headers = list("Access-Control-Request-Method" = "POST"), method = "OPTIONS")
rs = app$process_request(rq)

expect_equal(rs$body, "OK")
expect_equal(rs$content_type, "text/plain")
expect_equal(rs$get_header("Access-Control-Allow-Origin"), "*")
expect_equal(rs$get_header("Access-Control-Allow-Methods"), "POST, OPTIONS")
expect_equal(rs$get_header("Access-Control-Max-Age"), "86400")
expect_equal(rs$status_code, 200L)

rq = Request$new(path = "/nocors", headers = list("Access-Control-Request-Method" = "POST"), method = "OPTIONS")
rs = app$process_request(rq)
expect_equal(rs$body, "OK")
expect_equal(rs$content_type, "text/plain")
expect_false(rs$has_header("Access-Control-Allow-Origin"))
expect_false(rs$has_header("Access-Control-Allow-Methods"))
expect_false(rs$has_header("Access-Control-Max-Age"))

Try the RestRserve package in your browser

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

RestRserve documentation built on May 29, 2024, 8:18 a.m.