MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / apply_ranges

Method apply_ranges

dependencies/httplib/httplib.h:5508–5616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5506}
5507
5508inline void Server::apply_ranges(const Request &req, Response &res,
5509 std::string &content_type,
5510 std::string &boundary) {
5511 if (req.ranges.size() > 1) {
5512 boundary = detail::make_multipart_data_boundary();
5513
5514 auto it = res.headers.find("Content-Type");
5515 if (it != res.headers.end()) {
5516 content_type = it->second;
5517 res.headers.erase(it);
5518 }
5519
5520 res.headers.emplace("Content-Type",
5521 "multipart/byteranges; boundary=" + boundary);
5522 }
5523
5524 auto type = detail::encoding_type(req, res);
5525
5526 if (res.body.empty()) {
5527 if (res.content_length_ > 0) {
5528 size_t length = 0;
5529 if (req.ranges.empty()) {
5530 length = res.content_length_;
5531 } else if (req.ranges.size() == 1) {
5532 auto offsets =
5533 detail::get_range_offset_and_length(req, res.content_length_, 0);
5534 auto offset = offsets.first;
5535 length = offsets.second;
5536 auto content_range = detail::make_content_range_header_field(
5537 offset, length, res.content_length_);
5538 res.set_header("Content-Range", content_range);
5539 } else {
5540 length = detail::get_multipart_ranges_data_length(req, res, boundary,
5541 content_type);
5542 }
5543 res.set_header("Content-Length", std::to_string(length));
5544 } else {
5545 if (res.content_provider_) {
5546 if (res.is_chunked_content_provider_) {
5547 res.set_header("Transfer-Encoding", "chunked");
5548 if (type == detail::EncodingType::Gzip) {
5549 res.set_header("Content-Encoding", "gzip");
5550 } else if (type == detail::EncodingType::Brotli) {
5551 res.set_header("Content-Encoding", "br");
5552 }
5553 }
5554 }
5555 }
5556 } else {
5557 if (req.ranges.empty()) {
5558 ;
5559 } else if (req.ranges.size() == 1) {
5560 auto offsets =
5561 detail::get_range_offset_and_length(req, res.body.size(), 0);
5562 auto offset = offsets.first;
5563 auto length = offsets.second;
5564 auto content_range = detail::make_content_range_header_field(
5565 offset, length, res.body.size());

Callers

nothing calls this directly

Calls 15

encoding_typeFunction · 0.85
to_stringFunction · 0.85
set_headerMethod · 0.80
compressMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected