| 534 | SC_TEST_EXPECT(connection.response.sendHeaders()); |
| 535 | SC_TEST_EXPECT(connection.response.end()); |
| 536 | }; |
| 537 | |
| 538 | ClientConnection clientStorage; |
| 539 | HttpAsyncClient client; |
| 540 | ResponseCollector collector; |
| 541 | |
| 542 | TimeoutGuard timeout; |
| 543 | String url = StringEncoding::Ascii; |
| 544 | struct Context |
| 545 | { |
| 546 | ResponseCollector& collector; |
| 547 | HttpAsyncServer& httpServer; |
| 548 | } ctx = {collector, httpServer}; |
| 549 | |
| 550 | SC_TEST_EXPECT(client.init(clientStorage)); |
| 551 | SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/hello", port)); |
| 552 | |
| 553 | client.onResponse = [this, &ctx](HttpAsyncClientResponse& response) |
| 554 | { |
| 555 | ctx.collector.attach(response, |
| 556 | [this, &ctx](HttpAsyncClientResponse& completedResponse) |
| 557 | { |
| 558 | ctx.collector.detach(); |
| 559 | SC_TEST_EXPECT(completedResponse.getParser().statusCode == 200); |
| 560 | SC_TEST_EXPECT(ctx.collector.view().isEmpty()); |
| 561 | SC_TEST_EXPECT(ctx.httpServer.stop()); |
| 562 | }); |
| 563 | }; |
| 564 | client.onError = [this](Result result) { SC_TEST_EXPECT(result); }; |
| 565 | |
| 566 | SC_TEST_EXPECT(client.head(loop, url.view())); |
| 567 | |
| 568 | SC_TEST_EXPECT(timeout.start(loop, TimeMs{2000})); |
| 569 | SC_TEST_EXPECT(loop.run()); |
| 570 | SC_TEST_EXPECT(client.close()); |
| 571 | SC_TEST_EXPECT(httpServer.close()); |
| 572 | SC_TEST_EXPECT(loop.close()); |
| 573 | } |
| 574 | |
| 575 | void SC::HttpAsyncClientTest::commonMethodWrappers() |
| 576 | { |
| 577 | AsyncEventLoop loop; |
| 578 | SC_TEST_EXPECT(loop.create()); |
| 579 | |
| 580 | ServerConnection connections[2]; |
| 581 | HttpAsyncServer httpServer; |
| 582 | const uint16_t port = report.mapPort(26111); |
| 583 | SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections))); |
| 584 | SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port)); |
| 585 | |
| 586 | struct ServerContext |
| 587 | { |
| 588 | HttpAsyncClientTest* test = nullptr; |
| 589 | HttpConnection* connection = nullptr; |
| 590 | |
| 591 | Buffer patchBody; |
| 592 | |
| 593 | int patchRequests = 0; |
nothing calls this directly
no test coverage detected