From 1a3a175a2ca0c06a29e6a679c325395c8008a17e Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 11 Mar 2026 16:12:00 +0100 Subject: added streaming download of payloads http client Post (#824) * added streaming download of payloads in cpr client ::Post * curlclient Post streaming download * case sensitivity fixes for http headers * move over missing functionality from crpclient to httpclient --- src/zenhttp/httpclient_test.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/zenhttp/httpclient_test.cpp') diff --git a/src/zenhttp/httpclient_test.cpp b/src/zenhttp/httpclient_test.cpp index 2d949c546..5f3ad2455 100644 --- a/src/zenhttp/httpclient_test.cpp +++ b/src/zenhttp/httpclient_test.cpp @@ -514,6 +514,50 @@ TEST_CASE("httpclient.download") } } +TEST_CASE("httpclient.post-streaming") +{ + TestServerFixture Fixture; + ScopedTemporaryDirectory PostDir; + + SUBCASE("POST CbObject with TempFolderPath stays in memory when response is small") + { + HttpClient Client = Fixture.MakeClient(); + + CbObjectWriter Writer; + Writer.AddBool("streaming", false); + Writer.AddString("mode", "memory"); + CbObject Obj = Writer.Save(); + + HttpClient::Response Resp = Client.Post("/api/test/echo", Obj, {}, PostDir.Path()); + CHECK(Resp.IsSuccess()); + IoBufferFileReference _; + CHECK(!Resp.ResponsePayload.GetFileReference(_)); + CbObject RoundTripped = Resp.AsObject(); + CHECK(RoundTripped["streaming"].AsBool() == false); + CHECK_EQ(RoundTripped["mode"].AsString(), "memory"); + } + + SUBCASE("POST CbObject with TempFolderPath streams to file when response exceeds MaximumInMemoryDownloadSize") + { + HttpClientSettings Settings; + Settings.MaximumInMemoryDownloadSize = 4; + HttpClient Client = Fixture.MakeClient(Settings); + + CbObjectWriter Writer; + Writer.AddBool("streaming", true); + Writer.AddString("mode", "file"); + CbObject Obj = Writer.Save(); + + HttpClient::Response Resp = Client.Post("/api/test/echo", Obj, {}, PostDir.Path()); + CHECK(Resp.IsSuccess()); + IoBufferFileReference _; + CHECK(Resp.ResponsePayload.GetFileReference(_)); + CbObject RoundTripped = Resp.AsObject(); + CHECK(RoundTripped["streaming"].AsBool() == true); + CHECK_EQ(RoundTripped["mode"].AsString(), "file"); + } +} + TEST_CASE("httpclient.status-codes") { TestServerFixture Fixture; -- cgit v1.2.3