MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / send_with_content_provider

Method send_with_content_provider

external/httplib.h:7774–7851  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7772}
7773
7774inline std::unique_ptr<Response> ClientImpl::send_with_content_provider(
7775 Request &req, const char *body, size_t content_length,
7776 ContentProvider content_provider,
7777 ContentProviderWithoutLength content_provider_without_length,
7778 const std::string &content_type, Error &error) {
7779 if (!content_type.empty()) { req.set_header("Content-Type", content_type); }
7780
7781#ifdef CPPHTTPLIB_ZLIB_SUPPORT
7782 if (compress_) { req.set_header("Content-Encoding", "gzip"); }
7783#endif
7784
7785#ifdef CPPHTTPLIB_ZLIB_SUPPORT
7786 if (compress_ && !content_provider_without_length) {
7787 // TODO: Brotli support
7788 detail::gzip_compressor compressor;
7789
7790 if (content_provider) {
7791 auto ok = true;
7792 size_t offset = 0;
7793 DataSink data_sink;
7794
7795 data_sink.write = [&](const char *data, size_t data_len) -> bool {
7796 if (ok) {
7797 auto last = offset + data_len == content_length;
7798
7799 auto ret = compressor.compress(
7800 data, data_len, last,
7801 [&](const char *compressed_data, size_t compressed_data_len) {
7802 req.body.append(compressed_data, compressed_data_len);
7803 return true;
7804 });
7805
7806 if (ret) {
7807 offset += data_len;
7808 } else {
7809 ok = false;
7810 }
7811 }
7812 return ok;
7813 };
7814
7815 while (ok && offset < content_length) {
7816 if (!content_provider(offset, content_length - offset, data_sink)) {
7817 error = Error::Canceled;
7818 return nullptr;
7819 }
7820 }
7821 } else {
7822 if (!compressor.compress(body, content_length, true,
7823 [&](const char *data, size_t data_len) {
7824 req.body.append(data, data_len);
7825 return true;
7826 })) {
7827 error = Error::Compression;
7828 return nullptr;
7829 }
7830 }
7831 } else

Callers

nothing calls this directly

Calls 4

set_headerMethod · 0.80
compressMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected