diff options
Diffstat (limited to 'src/zenhttp/httpclient_test.cpp')
| -rw-r--r-- | src/zenhttp/httpclient_test.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/zenhttp/httpclient_test.cpp b/src/zenhttp/httpclient_test.cpp index b0e097a54..ea73ff7a3 100644 --- a/src/zenhttp/httpclient_test.cpp +++ b/src/zenhttp/httpclient_test.cpp @@ -300,6 +300,49 @@ struct TestServerFixture TEST_SUITE_BEGIN("http.httpclient"); +TEST_CASE("httpclient.response.findheader.arena") +{ + // Async client populates HeaderArena (raw "Key: Value\r\n" bytes); FindHeader + // scans it lazily without building the full KeyValueMap. Exercise arena scan + // path independent of any live HTTP transfer. + HttpClient::Response Resp; + Resp.HeaderArena = + "Content-Type: application/json\r\n" + "ETag: \"abc-123\"\r\n" + "Content-Length: 42\r\n" + "X-Amz-Request-Id: deadbeef\r\n" + "\r\n"; + + CHECK_EQ(Resp.FindHeader("Content-Type"), "application/json"); + CHECK_EQ(Resp.FindHeader("etag"), "\"abc-123\""); // case-insensitive + CHECK_EQ(Resp.FindHeader("CONTENT-LENGTH"), "42"); // case-insensitive + CHECK_EQ(Resp.FindHeader("x-amz-request-id"), "deadbeef"); + CHECK_EQ(Resp.FindHeader("missing"), ""); // absent + CHECK_EQ(Resp.FindHeader(""), ""); // empty name +} + +TEST_CASE("httpclient.response.findheader.map_fallback") +{ + // Sync client populates Header KeyValueMap; FindHeader falls back to it + // when HeaderArena is empty. + HttpClient::Response Resp; + Resp.Header->insert_or_assign("Content-Type", "text/plain"); + Resp.Header->insert_or_assign("ETag", "\"xyz\""); + + CHECK_EQ(Resp.FindHeader("content-type"), "text/plain"); + CHECK_EQ(Resp.FindHeader("ETag"), "\"xyz\""); + CHECK_EQ(Resp.FindHeader("missing"), ""); +} + +TEST_CASE("httpclient.response.findheader.arena_takes_priority") +{ + // If both populated (unusual), arena is scanned first. + HttpClient::Response Resp; + Resp.HeaderArena = "ETag: from-arena\r\n"; + Resp.Header->insert_or_assign("ETag", "from-map"); + CHECK_EQ(Resp.FindHeader("ETag"), "from-arena"); +} + TEST_CASE("httpclient.verbs") { TestServerFixture Fixture; |