gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitedcfce3fedcfce3f|||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 upmreedcfce3f/plugins/http1/native_http_server.hl

4.7 KB

  1. \* hl:http1 — the native HTTP/1.1 server. Subclass it (`inherit
  2. NativeHttpServer`) and answer `on request(req)` with a Response.
  3. AUTO-LISTEN: the file root IS the constructor and its last statement is
  4. listen(), so `new NativeHttpServer(port = 8888)` binds 8888 with no
  5. explicit call. *\
  6. /* Split from the former multi-class server.hl (mission 027). listen() is
  7. idempotent (the `listening` guard). A SUBCLASS does NOT inherit this run
  8. body — parent run bodies never run — so subclasses call listen() from
  9. their own root. No base `on request` handler here: the loop dispatches to
  10. the concrete instance's handlers, and old-form inheritance copies
  11. handlers — a base default would double-fire (mission 052). */
  12. \* One HTTP request reached this server — answer a Response (or hold
  13. req.respond for the streaming/deferred forms). *\
  14. emit request(
  15. Hybrid req \\ method, path, headers, body, bytes, params, respond
  16. )
  17. Number port = 8080 \\ the port bind() takes
  18. String host = "0.0.0.0" \\ the interface to bind
  19. String tls_cert = null \\ PEM certificate path — with tls_key, serve https
  20. String tls_key = null \\ PEM key path
  21. Number threads = 4 \\ I/O worker threads
  22. Number maxBody = 20971520 \\ largest request body read, bytes (default 20 MiB): a bigger Content-Length, or a chunked body growing past it, is answered 413 before it is read and the connection closed
  23. Boolean wsCheckOrigin = false \\ refuse a WebSocket upgrade whose Origin is foreign (not the Host, not in wsOrigins) with 403 before the 101; no Origin header = allowed
  24. String wsOrigins = "" \\ extra allowed WebSocket origins, comma-separated ('https://app.example.com' or bare 'app.example.com')
  25. Boolean listening = false \\ true after a successful bind
  26. Number #srcId = 0
  27. handleError(err) {
  28. console.log("Server error: " + err)
  29. }
  30. \* Bind the configured port (idempotent — an extra listen() is harmless).
  31. A FAILED BIND IS A REFUSAL, NOT A LINE OF PROSE (mission 286). This used
  32. to print `listen() failed: …` on stderr and return, so the process stayed
  33. alive with no socket and — because the event loop was still running for
  34. whatever else had registered — exited 0 or never exited at all. Every
  35. supervisor, deploy script and CI step was told the server started. A
  36. server that cannot serve says so and fails; the located form is below. *\
  37. listen() {
  38. if (listening == true) {
  39. return null
  40. }
  41. if (this.bind() != true) {
  42. hlError("hl:http1: listen() failed: could not bind port " + port + " on " + host + " — the port is already taken. The line just above, 'bind() failed on port " + port + "', names the process holding it: stop that process, or start this app on another port (--port N, or HL_PORT=N)")
  43. }
  44. return null
  45. }
  46. \* The bind itself, without the idempotence guard: a subclass that answers
  47. for its own double-listen policy (hl:web refuses one) still needs the one
  48. place where the socket is actually opened.
  49. ANSWERS true/false RATHER THAN RAISING (mission 286), because the caller
  50. owns the wording AND the location: hl:web can point its refusal at the
  51. manifest member that chose the port, which this file cannot see. Every
  52. caller must treat false as fatal — there is no third answer. *\
  53. bind() {
  54. srv = __native("http1.create_server", port, host, tls_cert, tls_key, threads, maxBody, wsCheckOrigin, wsOrigins)
  55. if (srv == null) {
  56. return false
  57. }
  58. listening = true
  59. #srcId = __native("eventloop.register", srv, "request")
  60. return true
  61. }
  62. \* Turn ON the RFC 6455 WebSocket engine for the port this server already
  63. bound: an Upgrade is answered inline in the I/O worker and
  64. the raw stream arrives at your own `on wsEvent` — WebSockets on the same
  65. port, no second listener. Separate from bind() because a plain HTTP
  66. server has no reason to start the engine thread. *\
  67. sockets() {
  68. __native("eventloop.register", __native("http1.ws_events"), "wsEvent")
  69. }
  70. \* Stop this server: the event source is retired (the loop can end by
  71. itself) and the native side joins the workers and closes the listener —
  72. the port is immediately free for a new bind(). Answers false when the
  73. server was not listening.
  74. SAFE FROM INSIDE A HANDLER (mission 260), and immediate — never deferred.
  75. The request you are answering is untouched: its socket is already your
  76. `req.respond` handle, so returning a Response after close() still reaches
  77. the client. A request that was parsed but can no longer be dispatched
  78. (the source is gone) is refused `503 Service Unavailable`; a connection
  79. accepted but not yet parsed is simply closed. *\
  80. close() {
  81. if (listening == false) {
  82. return false
  83. }
  84. listening = false
  85. __native("eventloop.unregister", #srcId)
  86. return __native("http1.close", port)
  87. }
  88. // Run body: the constructor's last act — bind the configured port.
  89. listen()

Branches

Latest commits

  • 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
  • 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
  • aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
  • ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
  • dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
  • d277633cident#27: README: identity access and the introspect endpointmre
  • e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
  • 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
  • a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
  • d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
  • ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
  • 80965c08ident#28: README says the deploy goes through the standbymre
  • 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre