louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // std/http/sse frames: the exact bytes of events and comments (Phase 5; |
| 2 | // the builder-built frames must equal the concatenated ones). |
| 3 | |
| 4 | import std/http/sse |
| 5 | import std/io |
| 6 | |
| 7 | pub fn main :: -> () / <io> |
| 8 | { |
| 9 | // The documented example. |
| 10 | io.println |
| 11 | (debug (sse.frame sse.Event(..sse.new_event "two\nlines", id: Some("42")))) |
| 12 | // Every field; newlines in `event:` and `id:` fold to spaces. |
| 13 | io.println |
| 14 | ( debug |
| 15 | ( sse.frame |
| 16 | sse.Event( ..sse.new_event "x" |
| 17 | , event: Some("up\ndate") |
| 18 | , id: Some("4\n2") |
| 19 | , retry: Some(3000) |
| 20 | ) |
| 21 | ) |
| 22 | ) |
| 23 | // No optional fields; empty data still writes one `data:` line. |
| 24 | io.println (debug (sse.frame (sse.new_event ""))) |
| 25 | // A trailing newline is a last, empty data line. |
| 26 | io.println (debug (sse.frame (sse.new_event "a\n"))) |
| 27 | // Comments: the heartbeat, multi-line, and empty. |
| 28 | io.println (debug (sse.comment "hb")) |
| 29 | io.println (debug (sse.comment "a\nb")) |
| 30 | io.println (debug (sse.comment "")) |
| 31 | } |
| 32 | //> b"id: 42\ndata: two\ndata: lines\n\n" |
| 33 | //> b"event: up date\nid: 4 2\nretry: 3000\ndata: x\n\n" |
| 34 | //> b"data: \n\n" |
| 35 | //> b"data: a\ndata: \n\n" |
| 36 | //> b": hb\n\n" |
| 37 | //> b": a\n: b\n\n" |
| 38 | //> b": \n\n" |