MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / apply_ranges

Method apply_ranges

examples/server/httplib.h:5916–6024  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5914}
5915
5916inline void Server::apply_ranges(const Request &req, Response &res,
5917 std::string &content_type,
5918 std::string &boundary) {
5919 if (req.ranges.size() > 1) {
5920 boundary = detail::make_multipart_data_boundary();
5921
5922 auto it = res.headers.find("Content-Type");
5923 if (it != res.headers.end()) {
5924 content_type = it->second;
5925 res.headers.erase(it);
5926 }
5927
5928 res.headers.emplace("Content-Type",
5929 "multipart/byteranges; boundary=" + boundary);
5930 }
5931
5932 auto type = detail::encoding_type(req, res);
5933
5934 if (res.body.empty()) {
5935 if (res.content_length_ > 0) {
5936 size_t length = 0;
5937 if (req.ranges.empty()) {
5938 length = res.content_length_;
5939 } else if (req.ranges.size() == 1) {
5940 auto offsets =
5941 detail::get_range_offset_and_length(req, res.content_length_, 0);
5942 auto offset = offsets.first;
5943 length = offsets.second;
5944 auto content_range = detail::make_content_range_header_field(
5945 offset, length, res.content_length_);
5946 res.set_header("Content-Range", content_range);
5947 } else {
5948 length = detail::get_multipart_ranges_data_length(req, res, boundary,
5949 content_type);
5950 }
5951 res.set_header("Content-Length", std::to_string(length));
5952 } else {
5953 if (res.content_provider_) {
5954 if (res.is_chunked_content_provider_) {
5955 res.set_header("Transfer-Encoding", "chunked");
5956 if (type == detail::EncodingType::Gzip) {
5957 res.set_header("Content-Encoding", "gzip");
5958 } else if (type == detail::EncodingType::Brotli) {
5959 res.set_header("Content-Encoding", "br");
5960 }
5961 }
5962 }
5963 }
5964 } else {
5965 if (req.ranges.empty()) {
5966 ;
5967 } else if (req.ranges.size() == 1) {
5968 auto offsets =
5969 detail::get_range_offset_and_length(req, res.body.size(), 0);
5970 auto offset = offsets.first;
5971 auto length = offsets.second;
5972 auto content_range = detail::make_content_range_header_field(
5973 offset, length, res.body.size());

Callers

nothing calls this directly

Calls 15

encoding_typeFunction · 0.85
findMethod · 0.80
set_headerMethod · 0.80
substrMethod · 0.80
compressMethod · 0.80
to_stringFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected