gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf2a2b0cef2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamref2a2b0ce/plugins/http1/server.hl

3.2 KB

  1. \* hl:http1 — module exports beside the class surface (NativeHttpServer,
  2. NativeWebSocketServer, Response, WsClient in their own files). *\
  3. \* Bind a plain HTTP/1.1 listener; answers the request event source. *\
  4. listen(
  5. Number port \\ the port to bind
  6. ) {
  7. return __native("http1.listen", port)
  8. }
  9. \* The full-featured constructor: interface, TLS pair, worker count. *\
  10. create_server(
  11. Number port \\ the port to bind
  12. String host = '0.0.0.0' \\ the interface
  13. String cert = null \\ PEM certificate path — with key, serve https
  14. String key = null \\ PEM key path
  15. Number threads = 4 \\ I/O worker threads
  16. Number maxBody = 20971520 \\ largest request body read, bytes; over it: 413
  17. Boolean wsCheckOrigin = false \\ 403 a WebSocket upgrade with a foreign Origin
  18. String wsOrigins = "" \\ extra allowed origins, comma-separated
  19. ) {
  20. return __native("http1.create_server", port, host, cert, key, threads, maxBody, wsCheckOrigin, wsOrigins)
  21. }
  22. \* A cookie-grade random token: n lowercase hex characters read from the
  23. KERNEL's CSPRNG, never a seeded PRNG — a session id is the only thing
  24. between a stranger and someone else's session (hl:math's random() is a
  25. clock-seeded xoshiro whose state a handful of outputs reveal). Lives here
  26. because the session cookie is an HTTP artifact. *\
  27. randomToken(
  28. Number n \\ how many hex characters
  29. ) {
  30. return __native("http1.random_token", n)
  31. }
  32. \* SERVER-SENT EVENTS (ticket #144) — the push channel, imported by name like any
  33. other export: import { sseStart, sseSend } from 'hl:http1'. A static or a method
  34. calls them; the browser build of a file that imports them binds each to a refusal
  35. that throws only if the browser CALLS it (hl:http1 ships no browser half).
  36. let conn = sseStart(req.respond) \\ the GET is now a text/event-stream
  37. sseSend(conn, JSON.stringify(row)) \\ one `data:` frame to that client
  38. A stream lives until its client goes: hl:http1 reaps a closed one at once (FIN) or
  39. at the next ":" heartbeat (every 5 s), and a push to it answers false. Plain HTTP
  40. only — on hl:http1's own TLS, sseStart answers null (end TLS in a proxy). *\
  41. \* Turn this request into a Server-Sent Events stream: writes the 200
  42. text/event-stream head and keeps the socket open. Answers the CONNECTION ID the
  43. other sse calls address, or null when the request was already answered (or is TLS). *\
  44. sseStart(
  45. Hybrid respond \\ the request's respond handle: req.respond
  46. ) {
  47. return respond.call("sse_start")
  48. }
  49. \* One frame to one stream: `data: <text>` and the blank line. A text with
  50. newlines continues the frame (a line after the first is its own field, e.g.
  51. 'id: 42'). Answers true when it was written, false when that stream is gone. *\
  52. sseSend(
  53. Number conn \\ the id sseStart answered
  54. String text \\ the frame's data, usually JSON.stringify(...)
  55. ) {
  56. return __native("http1.sse_send", conn, text) == 1
  57. }
  58. \* The same frame to every open stream; answers how many got it. *\
  59. sseBroadcast(
  60. String text \\ the frame's data
  61. ) {
  62. return __native("http1.sse_broadcast", text)
  63. }
  64. \* Is the stream still open? Asks the registry, pushes nothing. *\
  65. sseAlive(
  66. Number conn \\ the id sseStart answered
  67. ) {
  68. return __native("http1.sse_alive", conn) == 1
  69. }
  70. \* How many streams are open now. *\
  71. sseCount() {
  72. return __native("http1.sse_count")
  73. }

Branches

Latest commits

  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre
  • d7184f53log: batch live, #25 evidencemre
  • 5e25e816log: W61 mergedmre
  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre
  • 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre
  • 153c344bRestore organization metadata exposed by the whole-image comparisonmre
  • 917a1465Update status gate assertions for the referenced state rulemre
  • 3cdb02c6Own settings feedback styles and explain connection-state classesmre
  • 00d5d6c4Reference code-entry styles and nest code-browser media and pseudosmre
  • 3c425eddReference PR content styles and explain dynamic state classesmre
  • e46fa222Own shell feedback styles and retain documented selector formsmre
  • c26084c4Reference repository list styles and nest its breakpointmre
  • f3e196b5Document Markdown direct-child selector remaindersmre