| 429 | SC_TEST_EXPECT(eventLoop.create()); |
| 430 | |
| 431 | using HttpConnectionType = HttpAsyncConnection<2, 2, 8 * 1024, 8 * 1024>; |
| 432 | |
| 433 | HttpConnectionType connections[1]; |
| 434 | HttpAsyncServer httpServer; |
| 435 | const uint16_t serverPort = report.mapPort(6153); |
| 436 | SC_TEST_EXPECT(httpServer.init(Span<HttpConnectionType>(connections))); |
| 437 | SC_TEST_EXPECT(httpServer.start(eventLoop, "127.0.0.1", serverPort)); |
| 438 | |
| 439 | httpServer.onRequest = [this](HttpConnection& connection) |
| 440 | { |
| 441 | SC_TEST_EXPECT(connection.response.startResponse(418, "I'm a Teapot")); |
| 442 | SC_TEST_EXPECT(connection.response.addHeader("Content-Length", "0")); |
| 443 | SC_TEST_EXPECT(connection.response.sendHeaders()); |
| 444 | SC_TEST_EXPECT(connection.response.end()); |
| 445 | }; |
| 446 | |
| 447 | HttpTestClient client; |
| 448 | client.callback = [this, &httpServer](HttpTestClient& result) |
| 449 | { |
| 450 | StringView response(result.getResponse()); |
| 451 | SC_TEST_EXPECT(response.containsString("418 I'm a Teapot")); |
| 452 | SC_TEST_EXPECT(httpServer.stop()); |
| 453 | }; |
| 454 | |
| 455 | String endpoint = StringEncoding::Ascii; |
| 456 | SC_TEST_EXPECT(StringBuilder::format(endpoint, "http://127.0.0.1:{}/status", serverPort)); |
| 457 | SC_TEST_EXPECT(client.get(eventLoop, endpoint.view())); |
| 458 | |
| 459 | AsyncLoopTimeout timeout; |
| 460 | timeout.callback = [this](AsyncLoopTimeout::Result&) |
| 461 | { SC_TEST_EXPECT("Test never finished. Event Loop is stuck. Timeout expired." && false); }; |
| 462 | SC_TEST_EXPECT(timeout.start(eventLoop, TimeMs{2000})); |
| 463 | eventLoop.excludeFromActiveCount(timeout); |
| 464 | |
| 465 | SC_TEST_EXPECT(eventLoop.run()); |
| 466 | SC_TEST_EXPECT(httpServer.close()); |
| 467 | SC_TEST_EXPECT(eventLoop.close()); |
| 468 | } |
| 469 | |
| 470 | void SC::HttpAsyncServerTest::standardResponseStatuses() |
| 471 | { |
| 472 | struct ProbeResponse : public HttpResponse |
| 473 | { |
| 474 | using HttpOutgoingMessage::setHeaderMemory; |
| 475 | |
| 476 | [[nodiscard]] StringSpan written() const { return {responseHeaders.written(), false, StringEncoding::Ascii}; } |
nothing calls this directly
no test coverage detected