gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5cb5cf0e5cb5cf0eident#33: the code field's look moves into codestep.hl's Stylemre5cb5cf0e/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

  • 5cb5cf0eident#33: the code field's look moves into codestep.hl's Stylemre
  • f421cd60ident#33: the shell's own rules (user menu address, offline note, network probe) move into main.hl's Stylemre
  • c512fb96Merge branch 'f4-homesplit' into mainIdent
  • 07d1717c|||PR ident#40 home.hl is split into components, one per area: email step, identity form, identity list, app identity choice, time zone; each moves its faces with it, the email step is shared with embed.hl (#40.3, rest of #40.2)mre
  • 59e8fcc1ident#40.3: the app's identity choice is one component (components/chooseidentity.hl); its face chooseIdentity moves with itmre
  • e23efdfcident#40.3: the identity list is one component (components/identitylist.hl); its delete and face dropIdentity move with itmre
  • e24b59a6ident#40.3: the time zone is one component (components/timezone.hl); its face changeTimeZone moves with itmre
  • 8cbc5717ident#40.3: the email step is one component (components/emailstep.hl) placed by home.hl and embed.hlmre
  • 6fad3bd2Merge branch 'f3-codestep' into mainIdent
  • 51e387f2|||PR ident#40 the code step is one component (components/codestep.hl) placed by home.hl and embed.hl; its verify face, setCode, browserZone and verify call exist once (#40.2)mre
  • c28bddeeMerge branch 'f2-shell' into mainIdent
  • c3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mre
  • 060f3870ident#40.4: use the shell sign-out faces in regression gatesmre
  • 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
  • edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre
  • 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
  • c7eef14aMerge branch 'nv1-navigate' into mainIdent
  • 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
  • 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
  • 23971fb7ident#49: media queries in the language's @media formmre