Skip to content

Add Suave-style cookie session primitives to the ASP.NET Core Suave adapter#12

Merged
wallymathieu merged 3 commits into
masterfrom
copilot/fix-cookies-and-session-issue
Jun 6, 2026
Merged

Add Suave-style cookie session primitives to the ASP.NET Core Suave adapter#12
wallymathieu merged 3 commits into
masterfrom
copilot/fix-cookies-and-session-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

Suave-style cookie session flows were missing from the adapter, making it hard to port patterns that rely on statefulForSession and HttpContext.state. This change adds minimal session/cookie primitives aligned with the existing compositional WebPart API.

  • Session/cookie API surface

    • Added Filters.statefulForSession to gate routes on session availability.
    • Added HttpContext.state to retrieve ISession from the current request context.
    • Added Session.tryGet / Session.set helpers for typed session key access.
    • Added Request.Cookie.tryGet for cookie reads from HttpRequest.
  • Behavioral alignment

    • Session availability is now represented as Some/None in Suave-style flow composition instead of throwing when session middleware is absent.
    • Enables the canonical “counter in session cookie” pattern with existing >=> composition.
  • Example usage

    Filters.path "/session"
    >=> Filters.statefulForSession
    >=> (fun ctx ->
      match FSharpPlus.AspNetCore.Suave.HttpContext.state ctx with
      | Some store ->
        let current =
          store
          |> FSharpPlus.AspNetCore.Suave.Session.tryGet "counter"
          |> Option.defaultValue "0"
          |> int
        store |> FSharpPlus.AspNetCore.Suave.Session.set "counter" (string (current + 1))
        Successful.OK (sprintf "Hello %d time(s)" (current + 1)) ctx
      | None ->
        Successful.OK "No session available" ctx)

Copilot AI linked an issue Jun 6, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix cookies and session handling in Suave Add Suave-style cookie session primitives to the ASP.NET Core Suave adapter Jun 6, 2026
Copilot AI requested a review from wallymathieu June 6, 2026 09:25
@wallymathieu wallymathieu marked this pull request as ready for review June 6, 2026 10:37
@wallymathieu wallymathieu merged commit 04b39a9 into master Jun 6, 2026
1 check passed
@wallymathieu wallymathieu deleted the copilot/fix-cookies-and-session-issue branch June 6, 2026 10:37
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.

Cookies and session

2 participants