| 1691 | httpServer.onRequest = [this](HttpConnection& connection) |
| 1692 | { |
| 1693 | SC_TEST_EXPECT(connection.response.startResponse(200)); |
| 1694 | SC_TEST_EXPECT(connection.response.setChunkedTransferEncoding()); |
| 1695 | SC_TEST_EXPECT(connection.response.sendHeaders()); |
| 1696 | SC_TEST_EXPECT(connection.response.getWritableStream().write("hello")); |
| 1697 | SC_TEST_EXPECT(connection.response.getWritableStream().write(" world")); |
| 1698 | SC_TEST_EXPECT(connection.response.end()); |
| 1699 | }; |
| 1700 | |
| 1701 | ClientConnection clientStorage; |
| 1702 | HttpAsyncClient client; |
| 1703 | ResponseCollector collector; |
| 1704 | TimeoutGuard timeout; |
| 1705 | struct Context |
| 1706 | { |
| 1707 | ResponseCollector& collector; |
| 1708 | HttpAsyncServer& httpServer; |
| 1709 | } ctx = {collector, httpServer}; |
| 1710 | |
| 1711 | SC_TEST_EXPECT(client.init(clientStorage)); |
| 1712 | String url = StringEncoding::Ascii; |
| 1713 | SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/chunked", port)); |
| 1714 | |
| 1715 | client.onResponse = [this, &ctx](HttpAsyncClientResponse& response) |
| 1716 | { |
| 1717 | SC_TEST_EXPECT(response.getBodyFramingKind() == HttpBodyFramingKind::Chunked); |
| 1718 | ctx.collector.attach(response, |
| 1719 | [this, &ctx](HttpAsyncClientResponse& completedResponse) |
| 1720 | { |
| 1721 | ctx.collector.detach(); |
| 1722 | SC_TEST_EXPECT(completedResponse.getParser().statusCode == 200); |
| 1723 | SC_TEST_EXPECT(ctx.collector.view() == "hello world"); |
| 1724 | SC_TEST_EXPECT(ctx.httpServer.stop()); |
| 1725 | }); |
| 1726 | }; |
| 1727 | client.onError = [this](Result result) { SC_TEST_EXPECT(result); }; |
| 1728 | |
| 1729 | SC_TEST_EXPECT(timeout.start(loop, TimeMs{2000})); |
| 1730 | SC_TEST_EXPECT(client.get(loop, url.view())); |
| 1731 | SC_TEST_EXPECT(loop.run()); |
| 1732 | SC_TEST_EXPECT(httpServer.close()); |
| 1733 | SC_TEST_EXPECT(loop.close()); |
| 1734 | } |
| 1735 | |
| 1736 | void SC::HttpAsyncClientTest::chunkedResponseRejectsTrailers() |
| 1737 | { |
| 1738 | AsyncEventLoop loop; |
| 1739 | SC_TEST_EXPECT(loop.create()); |
| 1740 | |
| 1741 | ServerConnection connections[1]; |
| 1742 | HttpAsyncServer httpServer; |
| 1743 | const uint16_t port = report.mapPort(26109); |
| 1744 | SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections))); |
| 1745 | SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port)); |
| 1746 | |
| 1747 | httpServer.onRequest = [this](HttpConnection& connection) |
| 1748 | { |
| 1749 | SC_TEST_EXPECT(connection.response.startResponse(200)); |
| 1750 | SC_TEST_EXPECT(connection.response.addHeader("Transfer-Encoding", "chunked")); |
nothing calls this directly
no test coverage detected