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

Method get_multipart_content_provider

examples/server/httplib.h:6936–6976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6934}
6935
6936inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
6937 const std::string &boundary, const MultipartFormDataItems &items,
6938 const MultipartFormDataProviderItems &provider_items) {
6939 size_t cur_item = 0, cur_start = 0;
6940 // cur_item and cur_start are copied to within the std::function and maintain
6941 // state between successive calls
6942 return [&, cur_item, cur_start](size_t offset,
6943 DataSink &sink) mutable -> bool {
6944 if (!offset && items.size()) {
6945 sink.os << detail::serialize_multipart_formdata(items, boundary, false);
6946 return true;
6947 } else if (cur_item < provider_items.size()) {
6948 if (!cur_start) {
6949 const auto &begin = detail::serialize_multipart_formdata_item_begin(
6950 provider_items[cur_item], boundary);
6951 offset += begin.size();
6952 cur_start = offset;
6953 sink.os << begin;
6954 }
6955
6956 DataSink cur_sink;
6957 bool has_data = true;
6958 cur_sink.write = sink.write;
6959 cur_sink.done = [&]() { has_data = false; };
6960
6961 if (!provider_items[cur_item].provider(offset - cur_start, cur_sink))
6962 return false;
6963
6964 if (!has_data) {
6965 sink.os << detail::serialize_multipart_formdata_item_end();
6966 cur_item++;
6967 cur_start = 0;
6968 }
6969 return true;
6970 } else {
6971 sink.os << detail::serialize_multipart_formdata_finish(boundary);
6972 sink.done();
6973 return true;
6974 }
6975 };
6976}
6977
6978inline bool
6979ClientImpl::process_socket(const Socket &socket,

Callers

nothing calls this directly

Tested by

no test coverage detected