Repository navigation
Conversation
ac0864f to
024bcb3
Compare
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.
024bcb3 to
a390763
Compare
pa-devbot
left a comment
There was a problem hiding this comment.
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 theStopDuringHandlercomment that referenced the old socket'sclose_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-continueinterim 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):
HttpServer213/13 across 4 runs, legacyHttpServer13/13,ServerSocket230/30; no compiler warnings in the new files.- The implementation delta vs
HttpServer.cppis purely transport plumbing (per-connection objects instead of the connection-id token, thestate()check inon_disconnect, the "still active" guard inend_connection,close_connection()->active_connection()->close()instop());try_parseand the request loop are unchanged. - Checked the POSIX backend against the new code's assumptions:
send()re-checksm_openevery loop iteration, sostop()'s close makes in-flight writes return promptly instead of hittingWRITE_TIMEOUT;close()is idempotent and thread-safe, and the shell stays inert after the server is destroyed, as documented inAbstractServerSocketConnection.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 onhttp_1_1, seeHttpServer2.cppwherehttp_1_0is accepted); - handler throws -> 500 "The handler threw an exception." + close;
- null handler -> 500 "No handler is registered." + close;
Response.connection_close = trueset 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(); |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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".
Adds
HttpServer2, a parallel implementation ofAbstractHttpServeron the new per-connectionServerSocket2backends, with the existingHttpServeronAbstractServerSocketleft 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 sameAbstractHttpServercontract (request/response parsing, keep-alive, pipelining,Connection: close,Expect: 100-continue, handler contract, lifecycle) on the platform's defaultServerSocket2backend.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 itson_disconnectstate-checking go away.HttpServer2_Tests.{h,cpp}: 13 loopback tests mirroring theHttpServersuite, 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),
ServerSocket230/30, legacyHttpServer13/13, legacySockets30/30, full suite 20,947 / 0 / 5 (pre-existing audio skips). The WinSocket backend and the Clang-only CI legs are not compiled locally.