| 1638 | httpServer.onRequest = [this](HttpConnection& connection) |
| 1639 | { |
| 1640 | SC_TEST_EXPECT(connection.response.startResponse(200)); |
| 1641 | SC_TEST_EXPECT(connection.response.addHeader("Content-Length", "0")); |
| 1642 | SC_TEST_EXPECT(connection.response.sendHeaders()); |
| 1643 | SC_TEST_EXPECT(connection.response.end()); |
| 1644 | }; |
| 1645 | |
| 1646 | ClientConnection clientStorage; |
| 1647 | HttpAsyncClient client; |
| 1648 | ResponseCollector collector; |
| 1649 | TimeoutGuard timeout; |
| 1650 | struct Context |
| 1651 | { |
| 1652 | ResponseCollector& collector; |
| 1653 | HttpAsyncServer& httpServer; |
| 1654 | } ctx = {collector, httpServer}; |
| 1655 | |
| 1656 | SC_TEST_EXPECT(client.init(clientStorage)); |
| 1657 | String url = StringEncoding::Ascii; |
| 1658 | SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/empty", port)); |
| 1659 | |
| 1660 | client.onResponse = [this, &ctx](HttpAsyncClientResponse& response) |
| 1661 | { |
| 1662 | ctx.collector.attach(response, |
| 1663 | [this, &ctx](HttpAsyncClientResponse& completedResponse) |
| 1664 | { |
| 1665 | ctx.collector.detach(); |
| 1666 | SC_TEST_EXPECT(completedResponse.getParser().statusCode == 200); |
| 1667 | SC_TEST_EXPECT(ctx.collector.view().sizeInBytes() == 0); |
| 1668 | SC_TEST_EXPECT(ctx.httpServer.stop()); |
| 1669 | }); |
| 1670 | }; |
| 1671 | client.onError = [this](Result result) { SC_TEST_EXPECT(result); }; |
| 1672 | |
| 1673 | SC_TEST_EXPECT(timeout.start(loop, TimeMs{2000})); |
| 1674 | SC_TEST_EXPECT(client.get(loop, url.view())); |
| 1675 | SC_TEST_EXPECT(loop.run()); |
| 1676 | SC_TEST_EXPECT(httpServer.close()); |
| 1677 | SC_TEST_EXPECT(loop.close()); |
| 1678 | } |
| 1679 | |
| 1680 | void SC::HttpAsyncClientTest::chunkedResponse() |
| 1681 | { |
| 1682 | AsyncEventLoop loop; |
| 1683 | SC_TEST_EXPECT(loop.create()); |
| 1684 | |
| 1685 | ServerConnection connections[1]; |
| 1686 | HttpAsyncServer httpServer; |
| 1687 | const uint16_t port = report.mapPort(26106); |
| 1688 | SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections))); |
| 1689 | SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port)); |
| 1690 | |
| 1691 | httpServer.onRequest = [this](HttpConnection& connection) |
| 1692 | { |
| 1693 | SC_TEST_EXPECT(connection.response.startResponse(200)); |
| 1694 | SC_TEST_EXPECT(connection.response.setChunkedTransferEncoding()); |
nothing calls this directly
no test coverage detected