Skip to content

Commit

Permalink
Merge branch 'louisza-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bart6114 committed Apr 7, 2017
2 parents 2617e92 + 3fb1662 commit 2105cd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: jug
Type: Package
Title: A Simple Web Framework for R
Version: 0.1.6
Version: 0.1.6.9000
Authors@R: person("Bart", "Smeets", email = "bartsmeets86@gmail.com",
role = c("aut", "cre"))
URL: https://github.com/Bart6114/jug
Expand Down
5 changes: 4 additions & 1 deletion R/middleware_cors.R
Expand Up @@ -40,7 +40,10 @@ cors<-function(
func<-function(req, res, err){

if(req$method == "OPTIONS"){
res$set_header("Allow", allow_methods)
res$set_header("Access-Control-Allow-Methods", allow_methods)
res$set_header("Access-Control-Allow-Origin", allow_origin)
res$set_header("Access-Control-Allow-Headers", allow_headers)

return("") # equals stop processing
}

Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -19,6 +19,10 @@ Plugins:

## Changes

### v0.1.6.9000

- Fixed CORS preflight request bug (issue #15)

### v0.1.6

- Ability to specify `auto-unbox` value for json responses
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test_cors.R
Expand Up @@ -2,6 +2,21 @@ library(jug)

context("testing CORS functionality")

test_req_OPTIONS <-RawTestRequest$new()
test_req_OPTIONS$method("OPTIONS")

test_that("Preflight request receives the right headers",{

res<-jug() %>%
cors("/", allow_headers = "Authorization") %>%
process_test_request(test_req_OPTIONS$req)

expect_true('Access-Control-Allow-Origin' %in% names(res$headers))
expect_true('Access-Control-Allow-Methods' %in% names(res$headers))
expect_true('Access-Control-Allow-Headers' %in% names(res$headers))

})

test_req<-RawTestRequest$new()

test_that("Access-Control-Allow-Origin default is set to permissive",{
Expand Down

0 comments on commit 2105cd9

Please sign in to comment.