Skip to content

HTTP: add the HttpServer2 implementation on the ServerSocket2 backends - #1930

Open
pa-devbot wants to merge 2 commits into
mainfrom
add-httpserver2
Open

pa-devbot wants to merge 2 commits into
mainfrom
add-httpserver2

Conversation

@pa-devbot

@pa-devbot pa-devbot commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Adds HttpServer2, a parallel implementation of AbstractHttpServer on the new per-connection ServerSocket2 backends, with the existing HttpServer on AbstractServerSocket left untouched while the new shape is proven out.

Stacked on #1931 (the ServerSocket2 close-state fix this test suite exposed).

  • Common/Cpp/HttpServer/HttpServer2.{h,cpp}: the same AbstractHttpServer contract (request/response parsing, keep-alive, pipelining, Connection: close, Expect: 100-continue, handler contract, lifecycle) on the platform's default ServerSocket2 backend.
  • The transport's per-connection objects make the connection identity explicit: the socket's callbacks pass the connection they are about, and all I/O happens on that connection object. A response that outlives its connection is sent into the inert shell of the old connection (send() returns 0) instead of being refused by a connection id, and closing a connection can never touch a later client's socket — the old server's connection-id checks and its on_disconnect state-checking go away.
  • HttpServer2_Tests.{h,cpp}: 13 loopback tests mirroring the HttpServer suite, plus CMake (SerialPrograms/cmake/SourceFiles.cmake) and test-runner (ComputerPrograms_UnitTestRunner.cpp) wiring.

Local results: new suite 13/13 across ~15 runs (including full-suite runs for load), ServerSocket2 30/30, legacy HttpServer 13/13, legacy Sockets 30/30, full suite 20,947 / 0 / 5 (pre-existing audio skips). The WinSocket backend and the Clang-only CI legs are not compiled locally.

@pa-devbot
pa-devbot force-pushed the add-httpserver2 branch 4 times, most recently from ac0864f to 024bcb3 Compare November 18, 2026 19:31
A parallel implementation of AbstractHttpServer on the new per-connection
server socket API (ServerSocket2), leaving the existing HttpServer on
AbstractServerSocket untouched while the new shape is proven out:

- HttpServer2 implements the same AbstractHttpServer contract (request/
  response parsing, keep-alive, pipelining, Connection: close,
  Expect: 100-continue, handler contract, lifecycle) on the
  platform's default ServerSocket2 backend.
- The transport's per-connection objects make the connection identity
  explicit: the socket's callbacks pass the connection they are about,
  and all I/O happens on that connection object. A response that
  outlives its connection is sent into the inert shell of the old
  connection (send() returns 0) instead of being refused by a
  connection id, and closing a connection can never touch a later
  client's socket - the connection-id checks and the state-checking in
  the old server's on_disconnect/end_connection go away.
- 13 loopback tests (a mirror of the HttpServer suite) plus CMake and
  test-runner wiring.

@pa-devbot pa-devbot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: Question on test coverage: yes - all applicable corner cases from the old suite are covered.

  • The 13 new tests are a 1:1 mirror of the 13 tests in HttpServer_Tests.cpp: normalizing the type/class names makes the two files byte-identical (diff-verified; the only content delta is the StopDuringHandler comment that referenced the old socket's close_connection() disconnect suppression, which no longer applies). All 13 corner cases remain applicable on the new transport: request/response parsing, pipelining, Connection: close + reconnect, 400 malformed request line + recovery, 501 chunked (handler never called), 413 oversized content-length, 400 oversized header section arriving in one piece, >2 MiB buffer cap (closed without a response), Expect: 100-continue interim response, disconnect during handler (connection_alive() + discarded response), reconnect while the previous handler is still running (late-response discard - the old server's connection-id case, now the inert-shell case), stop() during handler + restart, second-client rejection.

Verified locally (Linux aarch64, default backend = POSIX):

  • HttpServer2 13/13 across 4 runs, legacy HttpServer 13/13, ServerSocket2 30/30; no compiler warnings in the new files.
  • The implementation delta vs HttpServer.cpp is purely transport plumbing (per-connection objects instead of the connection-id token, the state() check in on_disconnect, the "still active" guard in end_connection, close_connection() -> active_connection()->close() in stop()); try_parse and the request loop are unchanged.
  • Checked the POSIX backend against the new code's assumptions: send() re-checks m_open every loop iteration, so stop()'s close makes in-flight writes return promptly instead of hitting WRITE_TIMEOUT; close() is idempotent and thread-safe, and the shell stays inert after the server is destroyed, as documented in AbstractServerSocketConnection.h.

Before the old server is removed (optional, not blocking): the new suite pins down exactly what the old one pinned down, but a few implementation-defined behaviors are untested in both suites. Worth adding here so removing the legacy server costs no coverage:

  • HTTP/1.0 request -> response must carry Connection: close (keep-alive is gated on http_1_1, see HttpServer2.cpp where http_1_0 is accepted);
  • handler throws -> 500 "The handler threw an exception." + close;
  • null handler -> 500 "No handler is registered." + close;
  • Response.connection_close = true set by the handler on HTTP/1.1.

(The parser-limit paths - duplicate content-length, >100 headers, 505 on a bad version, malformed content-length, >8 KiB request line - are identical in both implementations and untested in either; lower priority.)

// close() makes in-flight sends return promptly. (If the connection
// task has already closed it, close() is a no-op.)
if (AbstractServerSocket2::ConnectionPtr active = socket->active_connection()){
active->close();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: Verified against the POSIX backend: ServerSocket2Connection_POSIX::send() re-checks m_open every loop iteration and close() clears it, so this close does interrupt a write that is in flight - the assumption in the comment above holds (same for the Qt backend per the ServerSocket2 (Qt) - close() under a stalled event thread test).

} // anonymous namespace


void add_tests_HttpServer2(UnitTestDatabase& database, ThreadPool& thread_pool){

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: All 13 corner cases of the old HttpServer suite are mirrored here (the files are byte-identical after normalizing names). One suggestion for before the old server is removed: add tests for the behaviors neither suite pins down - HTTP/1.0 (response must say Connection: close), handler throws -> 500, null handler -> 500, and Response.connection_close from the handler. Details in the summary.

Four more HttpServer2 tests for implementation-defined behaviors that
no suite pins down, so removing the legacy server later costs no
coverage:

- HTTP/1.0 requests are not kept alive (response carries
  "Connection: close" and the connection is closed after it);
- a handler that throws gets a 500 with a fixed body and the
  connection is closed;
- a request with no handler registered gets a 500 and the connection
  is closed;
- a handler can opt a keep-alive request out of keep-alive with
  "response.connection_close".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant