gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2ef23df02ef23df0gitoria#40: the browser gate reads the title without the #Nmre2ef23df0/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

  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre
  • 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre
  • 4b98ab62gitoria: an ident access key (idt_) works as the git password; read key clones only, bad key 401, ident down 503 (ident#27); gate tests/ident-access-gitoria.mjs in deploy.shmre
  • 1185f686gitoria#36: a failed return from tickets shows a note on the settings page and leaves one log line per outcome; no code is exchangedmre
  • 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
  • 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
  • 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
  • a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
  • 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
  • 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
  • 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
  • a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
  • 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre