Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for handling CORS preflight requests #714

Open
wants to merge 18 commits into
base: v5-development
Choose a base branch
from

Conversation

jurakin
Copy link

@jurakin jurakin commented Jun 1, 2024

Description

This pull request adds support for handling CORS preflight requests in the routing system. The router will respond to OPTIONS requests only when the route actually exists and a preflight setting is enabled. The setting is disabled by default.

Changes

  • Added a preflight setting to enable handling of preflight requests.
  • When the setting is enabled, the router responds to OPTIONS requests with status 200 OK and no content, following the MDN documentation.
  • Added unit tests and README documentation.

Usage

// single route
SimpleRouter::form('foo', function () {
    // ...
})->setSettings(['preflight' => true]);

// group routes
SimpleRouter::group(['preflight' => true], function () {
    SimpleRouter::form('foo', function() {
        // ...
    });
});
  • Requesting OPTIONS /foo will return HTTP/1.1 200 OK.
  • Requesting POST /foo will proceed normally.

skipperbent and others added 18 commits November 21, 2023 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants