gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0ee5a6f20ee5a6f2Tickets conductor: T36 resumedmre0ee5a6f2/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

  • 0ee5a6f2Tickets conductor: T36 resumedmre
  • 9149c165Tickets conductor: T36 diagnosismre
  • 91713313Tickets conductor: T36 report 1mre
  • 756315d2Tickets conductor: T36 startedmre
  • 0814ce6bTickets conductor: brief 025 tickets#36 style formmre
  • 1b6916c4Tickets conductor: Atlas handover tickets#36mre
  • aab95226Tickets conductor: worldapi-conductor paths, deploy blocker = read-only diskmre
  • 6372b06dTickets conductor: worker port slotmre
  • 836af31cTickets conductor: token pathsmre
  • b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre