GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ignore ranges for unknown-length streams (#2465) · yhirose/cpp-httplib@c7ba963

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • httplib.h
  • test
    • test.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎httplib.h‎

Copy file name to clipboardExpand all lines: httplib.h
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8443,6 +8443,14 @@ inline void coalesce_ranges(Ranges &ranges, size_t content_length) {
84438443

84448444
inline bool range_error(Request &req, Response &res) {
84458445
if (!req.ranges.empty() && 200 <= res.status && res.status < 300) {
8446+
if (res.body.empty() && res.content_provider_ && res.content_length_ == 0) {
8447+
req.ranges.clear();
8448+
if (res.status == StatusCode::PartialContent_206) {
8449+
res.status = StatusCode::OK_200;
8450+
}
8451+
return false;
8452+
}
8453+
84468454
ssize_t content_len = static_cast<ssize_t>(
84478455
res.content_length_ ? res.content_length_ : res.body.size());
84488456

Collapse file

‎test/test.cc‎

Copy file name to clipboardExpand all lines: test/test.cc
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,6 +3718,23 @@ class ServerTest : public ::testing::Test {
37183718
return true;
37193719
});
37203720
})
3721+
.Get("/streamed-without-length",
3722+
[&](const Request & /*req*/, Response &res) {
3723+
auto data = new std::string("abcdefg");
3724+
res.set_content_provider(
3725+
"text/plain",
3726+
[data](size_t offset, DataSink &sink) {
3727+
if (offset < data->size()) {
3728+
sink.os << data->substr(offset);
3729+
}
3730+
sink.done();
3731+
return true;
3732+
},
3733+
[data](bool success) {
3734+
EXPECT_TRUE(success);
3735+
delete data;
3736+
});
3737+
})
37213738
.Get("/streamed-with-range",
37223739
[&](const Request &req, Response &res) {
37233740
auto data = new std::string("abcdefg");
@@ -5197,6 +5214,16 @@ TEST_F(ServerTest, GetStreamed) {
51975214
EXPECT_EQ(std::string("aaabbb"), res->body);
51985215
}
51995216

5217+
TEST_F(ServerTest, GetStreamedWithoutLengthWithRange) {
5218+
auto res =
5219+
cli_.Get("/streamed-without-length", {make_range_header({{0, -1}})});
5220+
ASSERT_TRUE(res);
5221+
EXPECT_EQ(StatusCode::OK_200, res->status);
5222+
EXPECT_EQ(false, res->has_header("Content-Length"));
5223+
EXPECT_EQ(false, res->has_header("Content-Range"));
5224+
EXPECT_EQ(std::string("abcdefg"), res->body);
5225+
}
5226+
52005227
TEST_F(ServerTest, GetStreamedWithRange1) {
52015228
auto res = cli_.Get("/streamed-with-range", {{make_range_header({{3, 5}})}});
52025229
ASSERT_TRUE(res);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.