summaryrefslogtreecommitdiff
path: root/Network/Wai/Middleware/Braid/DESIGN.md
blob: 90c6016db1c9838f800f45d96249751c4f1d4080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Braid Middleware Design

**Goal**: Implement HTTP Keep-Alive mechanism for Braid updates to support real-time streams.

## Current State
`Network/Wai/Middleware/Braid.hs` implements the Braid protocol headers but lacks a robust mechanism to keep the connection open and push updates.

## Design Requirements

1.  **Connection Management**:
    - Identify Braid subscriptions via headers.
    - Keep the response body open (streaming response).
    - Handle client disconnects gracefully.

2.  **Update Channel**:
    - Use a `TChan` or `BroadcastChan` to signal updates to the connection handler.
    - When a resource changes, push a new Braid frame to the open stream.

3.  **Frame Format**:
    - Adhere to Braid spec for patch frames.
    - `Content-Type: application/json` (or relevant type).
    - `Merge-Type: braid`.

## Implementation Plan
1.  Modify middleware to hijack response for Braid requests.
2.  Spawn a lightweight thread to listen on an update channel.
3.  Stream chunks to the client.