Skip to content

README: answer CORS preflights before creating a session - #18

Open
taplin wants to merge 1 commit into
mainfrom
readme-preflight
Open

taplin wants to merge 1 commit into
mainfrom
readme-preflight

Conversation

@taplin

@taplin taplin commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

The Perfect-NIO example in the README has a gap: a browser's CORS preflight (OPTIONS, sent without cookies) went through loadSession, so each one created and stored a new session, ran the page handler and got a Set-Cookie.

The example now answers OPTIONS at the top of loadSession with an empty 204 (throw TerminationType.criteriaFailed(.noContent)). A new paragraph explains why, and says that an app accepting cross-origin requests needs to answer preflights from acceptable origins with Access-Control-* headers. The intro now says Perfect-NIO 0.2, which is the version the example was checked against.

Checked: both README snippets, unchanged apart from imports, build with warnings as errors against Perfect-NIO 0.2.0 and this branch. In a running server with a counting driver:

  • Before: three preflights returned 200 visits: 1 with a new cookie each time, and created 3 sessions.
  • After: they return 204 with no cookie and create 0 sessions, and GET still returns 200 with the session cookie.

Docs only, so no release is needed.

🤖 Generated with Claude Code

The Perfect-NIO example created and stored a new session, and ran the
handler, for every OPTIONS preflight, since preflights carry no cookies.
Answer them with an empty 204 at the top of loadSession instead, and say
what a cross-origin app has to add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant