Match an If-Range date exactly against Last-Modified (#2707)

* Match an If-Range date exactly against Last-Modified

* Shorten the If-Range date comments

---------

Co-authored-by: yhirose <yuji.hirose.bug@gmail.com>
This commit is contained in:
Leng Niuandyhirose authored and GitHub committed 2026-12-03 14:28:25 -05:00
1 parent 3091751b5d
commit 4e6226d7af
2 files changed
+27 -5

No files matched your search

+25 -3
View File
@@ -27144,13 +27144,35 @@ TEST(ETagTest, IfRangeWithDate) {
EXPECT_EQ(200, res3->status);
EXPECT_EQ(content, res3->body);
// Range request with future If-Range date: should get 206
// Range request with future If-Range date: should get 200 (full content)
Headers h4 = {{"Range", "bytes=0-4"},
{"If-Range", "Sun, 01 Jan 2099 00:00:00 GMT"}};
auto res4 = cli.Get("/static/if_range_date_testfile.txt", h4);
ASSERT_TRUE(res4);
EXPECT_EQ(206, res4->status);
EXPECT_EQ("ABCDE", res4->body);
EXPECT_EQ(200, res4->status);
EXPECT_EQ(content, res4->body);
#if defined(__APPLE__) || defined(__linux__)
// File replaced by one with an older mtime: should get 200 (full content)
const std::string replaced = "abcdefghij9876543210";
{
std::ofstream ofs(fname);
ofs << replaced;
ASSERT_TRUE(ofs.good());
}
struct timeval times[2];
times[0].tv_sec = time(nullptr);
times[0].tv_usec = 0;
times[1].tv_sec = time(nullptr) - 3600;
times[1].tv_usec = 0;
ASSERT_EQ(0, utimes(fname, times));
Headers h5 = {{"Range", "bytes=5-9"}, {"If-Range", last_modified}};
auto res5 = cli.Get("/static/if_range_date_testfile.txt", h5);
ASSERT_TRUE(res5);
EXPECT_EQ(200, res5->status);
EXPECT_EQ(replaced, res5->body);
#endif
svr.stop();
t.join();