Skip to content

Proposal: Support OPTIONS requests #11

Open
@koffeinfrei

Description

@koffeinfrei

I'd like to discuss adding the possibility to handle OPTIONS requests as well in the handler.

This would allow to handle CORS requests that initiate a Preflight request.

The handler could then act depending on the request method, as shown in the following example:

class Handler
  def run(body, headers)
    if headers['REQUEST_METHOD'] == 'OPTIONS'
      return [
        [],
        {
          'Allow' => 'POST, GET, OPTIONS',
          'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS',
          'Access-Control-Allow-Origin' => '*',
          'Access-Control-Allow-Headers' => 'Accept'
        }
      ]
    end

    # ....
end

The change is backwards compatible, we'd only have to add one more route to sinatra.

We could also discuss to allow all available request methods.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions