diff --git a/httplib.h b/httplib.h index a2057f2..71d9a13 100644 --- a/httplib.h +++ b/httplib.h @@ -8473,12 +8473,8 @@ inline bool Server::check_if_not_modified(const Request &req, Response &res, // simplified implementation requires exact matches. auto ret = detail::split_find(val.data(), val.data() + val.size(), ',', [&](const char *b, const char *e) { - auto len = static_cast(e - b); - if (len == 1 && *b == '*') return true; - if (len == etag.size() && - std::equal(b, e, etag.begin())) - return true; - return false; + return std::equal(b, e, "*") || + std::equal(b, e, etag.begin()); }); if (ret) { diff --git a/test/test.cc b/test/test.cc index 0380acf..b975d5a 100644 --- a/test/test.cc +++ b/test/test.cc @@ -12751,6 +12751,26 @@ TEST(ETagTest, StaticFileETagAndIfNoneMatch) { std::remove(fname); } +TEST(ETagTest, StaticFileETagIfNoneMatchStarNotFound) { + using namespace httplib; + + Server svr; + svr.set_mount_point("/static", "."); + auto t = std::thread([&]() { svr.listen("localhost", 8090); }); + svr.wait_until_ready(); + + Client cli("localhost", 8090); + + // Send If-None-Match: * to a non-existent file + Headers h = {{"If-None-Match", "*"}}; + auto res = cli.Get("/static/etag_testfile_notfound.txt", h); + ASSERT_TRUE(res); + EXPECT_EQ(404, res->status); + + svr.stop(); + t.join(); +} + TEST(ETagTest, LastModifiedAndIfModifiedSince) { using namespace httplib; @@ -13085,16 +13105,4 @@ TEST(ETagTest, IfRangeWithMalformedETag) { svr.stop(); t.join(); std::remove(fname); -} - -TEST(ETagTest, DateParsingAndMtimeNegative) { - using namespace httplib; - - // parse_http_date should return -1 for invalid format - time_t parsed = detail::parse_http_date("this is not a date"); - EXPECT_EQ(static_cast(-1), parsed); - - // file_mtime_to_http_date returns empty string for negative mtime - std::string s = detail::file_mtime_to_http_date(static_cast(-1)); - EXPECT_TRUE(s.empty()); -} +} \ No newline at end of file