plumber icon indicating copy to clipboard operation
plumber copied to clipboard

Connection is closed on OPTIONS requests

Open satello opened this issue 6 years ago • 2 comments

Setting the Connection header for CORS preflight requests does not work with Plumber

#* @filter cors
cors <- function(res) {
  res$setHeader("Access-Control-Allow-Origin", "*")
  res$setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
  res$setHeader("Connection", "Keep-Alive")
  res$setHeader("Keep-Alive", "timeout=300")

  plumber::forward()
}

#* @options /opt
options <- function() {}

#* @post /opt
optimizeData <- function() {...}

The OPTIONS response comes back with the headers:

Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Origin: *
Connection: close
Keep-Alive: timeout=300

and the browser doesn't send the subsequent POST request

satello avatar Jun 29 '18 15:06 satello

This no longer the case, and I'm pretty sure it was fixed in #318.

atheriel avatar Feb 08 '21 14:02 atheriel

In the plumber.R file, you need to add a filter that handles OPTIONS CORS preflight requests from web browsers and returns code 200 and an empty list(); the code is here https://github.com/rstudio/plumber/issues/66#issuecomment-418660334

Kvit avatar Feb 12 '23 17:02 Kvit