You've already forked cpp-httplib
Change uint64_t to size_t
This commit is contained in:
91
httplib.h
91
httplib.h
@ -577,8 +577,8 @@ using Headers =
|
|||||||
using Params = std::multimap<std::string, std::string>;
|
using Params = std::multimap<std::string, std::string>;
|
||||||
using Match = std::smatch;
|
using Match = std::smatch;
|
||||||
|
|
||||||
using DownloadProgress = std::function<bool(uint64_t current, uint64_t total)>;
|
using DownloadProgress = std::function<bool(size_t current, size_t total)>;
|
||||||
using UploadProgress = std::function<bool(uint64_t current, uint64_t total)>;
|
using UploadProgress = std::function<bool(size_t current, size_t total)>;
|
||||||
|
|
||||||
struct Response;
|
struct Response;
|
||||||
using ResponseHandler = std::function<bool(const Response &response)>;
|
using ResponseHandler = std::function<bool(const Response &response)>;
|
||||||
@ -674,9 +674,8 @@ struct FormDataProvider {
|
|||||||
};
|
};
|
||||||
using FormDataProviderItems = std::vector<FormDataProvider>;
|
using FormDataProviderItems = std::vector<FormDataProvider>;
|
||||||
|
|
||||||
using ContentReceiverWithProgress =
|
using ContentReceiverWithProgress = std::function<bool(
|
||||||
std::function<bool(const char *data, size_t data_length, uint64_t offset,
|
const char *data, size_t data_length, size_t offset, size_t total_length)>;
|
||||||
uint64_t total_length)>;
|
|
||||||
|
|
||||||
using ContentReceiver =
|
using ContentReceiver =
|
||||||
std::function<bool(const char *data, size_t data_length)>;
|
std::function<bool(const char *data, size_t data_length)>;
|
||||||
@ -744,7 +743,7 @@ struct Request {
|
|||||||
bool has_header(const std::string &key) const;
|
bool has_header(const std::string &key) const;
|
||||||
std::string get_header_value(const std::string &key, const char *def = "",
|
std::string get_header_value(const std::string &key, const char *def = "",
|
||||||
size_t id = 0) const;
|
size_t id = 0) const;
|
||||||
uint64_t get_header_value_u64(const std::string &key, uint64_t def = 0,
|
size_t get_header_value_u64(const std::string &key, size_t def = 0,
|
||||||
size_t id = 0) const;
|
size_t id = 0) const;
|
||||||
size_t get_header_value_count(const std::string &key) const;
|
size_t get_header_value_count(const std::string &key) const;
|
||||||
void set_header(const std::string &key, const std::string &val);
|
void set_header(const std::string &key, const std::string &val);
|
||||||
@ -781,7 +780,7 @@ struct Response {
|
|||||||
bool has_header(const std::string &key) const;
|
bool has_header(const std::string &key) const;
|
||||||
std::string get_header_value(const std::string &key, const char *def = "",
|
std::string get_header_value(const std::string &key, const char *def = "",
|
||||||
size_t id = 0) const;
|
size_t id = 0) const;
|
||||||
uint64_t get_header_value_u64(const std::string &key, uint64_t def = 0,
|
size_t get_header_value_u64(const std::string &key, size_t def = 0,
|
||||||
size_t id = 0) const;
|
size_t id = 0) const;
|
||||||
size_t get_header_value_count(const std::string &key) const;
|
size_t get_header_value_count(const std::string &key) const;
|
||||||
void set_header(const std::string &key, const std::string &val);
|
void set_header(const std::string &key, const std::string &val);
|
||||||
@ -1334,8 +1333,8 @@ public:
|
|||||||
std::string get_request_header_value(const std::string &key,
|
std::string get_request_header_value(const std::string &key,
|
||||||
const char *def = "",
|
const char *def = "",
|
||||||
size_t id = 0) const;
|
size_t id = 0) const;
|
||||||
uint64_t get_request_header_value_u64(const std::string &key,
|
size_t get_request_header_value_u64(const std::string &key, size_t def = 0,
|
||||||
uint64_t def = 0, size_t id = 0) const;
|
size_t id = 0) const;
|
||||||
size_t get_request_header_value_count(const std::string &key) const;
|
size_t get_request_header_value_count(const std::string &key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -2010,8 +2009,8 @@ inline bool is_numeric(const std::string &str) {
|
|||||||
[](unsigned char c) { return std::isdigit(c); });
|
[](unsigned char c) { return std::isdigit(c); });
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t get_header_value_u64(const Headers &headers,
|
inline size_t get_header_value_u64(const Headers &headers,
|
||||||
const std::string &key, uint64_t def,
|
const std::string &key, size_t def,
|
||||||
size_t id, bool &is_invalid_value) {
|
size_t id, bool &is_invalid_value) {
|
||||||
is_invalid_value = false;
|
is_invalid_value = false;
|
||||||
auto rng = headers.equal_range(key);
|
auto rng = headers.equal_range(key);
|
||||||
@ -2027,8 +2026,8 @@ inline uint64_t get_header_value_u64(const Headers &headers,
|
|||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t get_header_value_u64(const Headers &headers,
|
inline size_t get_header_value_u64(const Headers &headers,
|
||||||
const std::string &key, uint64_t def,
|
const std::string &key, size_t def,
|
||||||
size_t id) {
|
size_t id) {
|
||||||
bool dummy = false;
|
bool dummy = false;
|
||||||
return get_header_value_u64(headers, key, def, id, dummy);
|
return get_header_value_u64(headers, key, def, id, dummy);
|
||||||
@ -2036,13 +2035,13 @@ inline uint64_t get_header_value_u64(const Headers &headers,
|
|||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
inline uint64_t Request::get_header_value_u64(const std::string &key,
|
inline size_t Request::get_header_value_u64(const std::string &key, size_t def,
|
||||||
uint64_t def, size_t id) const {
|
size_t id) const {
|
||||||
return detail::get_header_value_u64(headers, key, def, id);
|
return detail::get_header_value_u64(headers, key, def, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t Response::get_header_value_u64(const std::string &key,
|
inline size_t Response::get_header_value_u64(const std::string &key, size_t def,
|
||||||
uint64_t def, size_t id) const {
|
size_t id) const {
|
||||||
return detail::get_header_value_u64(headers, key, def, id);
|
return detail::get_header_value_u64(headers, key, def, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2228,8 +2227,8 @@ inline std::ostream &operator<<(std::ostream &os, const Error &obj) {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t Result::get_request_header_value_u64(const std::string &key,
|
inline size_t Result::get_request_header_value_u64(const std::string &key,
|
||||||
uint64_t def,
|
size_t def,
|
||||||
size_t id) const {
|
size_t id) const {
|
||||||
return detail::get_header_value_u64(request_headers_, key, def, id);
|
return detail::get_header_value_u64(request_headers_, key, def, id);
|
||||||
}
|
}
|
||||||
@ -4617,19 +4616,19 @@ inline bool read_headers(Stream &strm, Headers &headers) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool read_content_with_length(Stream &strm, uint64_t len,
|
inline bool read_content_with_length(Stream &strm, size_t len,
|
||||||
DownloadProgress progress,
|
DownloadProgress progress,
|
||||||
ContentReceiverWithProgress out) {
|
ContentReceiverWithProgress out) {
|
||||||
char buf[CPPHTTPLIB_RECV_BUFSIZ];
|
char buf[CPPHTTPLIB_RECV_BUFSIZ];
|
||||||
|
|
||||||
uint64_t r = 0;
|
size_t r = 0;
|
||||||
while (r < len) {
|
while (r < len) {
|
||||||
auto read_len = static_cast<size_t>(len - r);
|
auto read_len = static_cast<size_t>(len - r);
|
||||||
auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));
|
auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));
|
||||||
if (n <= 0) { return false; }
|
if (n <= 0) { return false; }
|
||||||
|
|
||||||
if (!out(buf, static_cast<size_t>(n), r, len)) { return false; }
|
if (!out(buf, static_cast<size_t>(n), r, len)) { return false; }
|
||||||
r += static_cast<uint64_t>(n);
|
r += static_cast<size_t>(n);
|
||||||
|
|
||||||
if (progress) {
|
if (progress) {
|
||||||
if (!progress(r, len)) { return false; }
|
if (!progress(r, len)) { return false; }
|
||||||
@ -4639,14 +4638,14 @@ inline bool read_content_with_length(Stream &strm, uint64_t len,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void skip_content_with_length(Stream &strm, uint64_t len) {
|
inline void skip_content_with_length(Stream &strm, size_t len) {
|
||||||
char buf[CPPHTTPLIB_RECV_BUFSIZ];
|
char buf[CPPHTTPLIB_RECV_BUFSIZ];
|
||||||
uint64_t r = 0;
|
size_t r = 0;
|
||||||
while (r < len) {
|
while (r < len) {
|
||||||
auto read_len = static_cast<size_t>(len - r);
|
auto read_len = static_cast<size_t>(len - r);
|
||||||
auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));
|
auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));
|
||||||
if (n <= 0) { return; }
|
if (n <= 0) { return; }
|
||||||
r += static_cast<uint64_t>(n);
|
r += static_cast<size_t>(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4660,7 +4659,7 @@ inline ReadContentResult
|
|||||||
read_content_without_length(Stream &strm, size_t payload_max_length,
|
read_content_without_length(Stream &strm, size_t payload_max_length,
|
||||||
ContentReceiverWithProgress out) {
|
ContentReceiverWithProgress out) {
|
||||||
char buf[CPPHTTPLIB_RECV_BUFSIZ];
|
char buf[CPPHTTPLIB_RECV_BUFSIZ];
|
||||||
uint64_t r = 0;
|
size_t r = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ);
|
auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ);
|
||||||
if (n == 0) { return ReadContentResult::Success; }
|
if (n == 0) { return ReadContentResult::Success; }
|
||||||
@ -4668,14 +4667,14 @@ read_content_without_length(Stream &strm, size_t payload_max_length,
|
|||||||
|
|
||||||
// Check if adding this data would exceed the payload limit
|
// Check if adding this data would exceed the payload limit
|
||||||
if (r > payload_max_length ||
|
if (r > payload_max_length ||
|
||||||
payload_max_length - r < static_cast<uint64_t>(n)) {
|
payload_max_length - r < static_cast<size_t>(n)) {
|
||||||
return ReadContentResult::PayloadTooLarge;
|
return ReadContentResult::PayloadTooLarge;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!out(buf, static_cast<size_t>(n), r, 0)) {
|
if (!out(buf, static_cast<size_t>(n), r, 0)) {
|
||||||
return ReadContentResult::Error;
|
return ReadContentResult::Error;
|
||||||
}
|
}
|
||||||
r += static_cast<uint64_t>(n);
|
r += static_cast<size_t>(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReadContentResult::Success;
|
return ReadContentResult::Success;
|
||||||
@ -4693,7 +4692,7 @@ inline ReadContentResult read_content_chunked(Stream &strm, T &x,
|
|||||||
if (!line_reader.getline()) { return ReadContentResult::Error; }
|
if (!line_reader.getline()) { return ReadContentResult::Error; }
|
||||||
|
|
||||||
unsigned long chunk_len;
|
unsigned long chunk_len;
|
||||||
uint64_t total_len = 0;
|
size_t total_len = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
char *end_ptr;
|
char *end_ptr;
|
||||||
|
|
||||||
@ -4845,7 +4844,7 @@ bool prepare_content_receiver(T &x, int &status,
|
|||||||
if (decompressor) {
|
if (decompressor) {
|
||||||
if (decompressor->is_valid()) {
|
if (decompressor->is_valid()) {
|
||||||
ContentReceiverWithProgress out = [&](const char *buf, size_t n,
|
ContentReceiverWithProgress out = [&](const char *buf, size_t n,
|
||||||
uint64_t off, uint64_t len) {
|
size_t off, size_t len) {
|
||||||
return decompressor->decompress(buf, n,
|
return decompressor->decompress(buf, n,
|
||||||
[&](const char *buf2, size_t n2) {
|
[&](const char *buf2, size_t n2) {
|
||||||
return receiver(buf2, n2, off, len);
|
return receiver(buf2, n2, off, len);
|
||||||
@ -4859,8 +4858,8 @@ bool prepare_content_receiver(T &x, int &status,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off,
|
ContentReceiverWithProgress out = [&](const char *buf, size_t n, size_t off,
|
||||||
uint64_t len) {
|
size_t len) {
|
||||||
return receiver(buf, n, off, len);
|
return receiver(buf, n, off, len);
|
||||||
};
|
};
|
||||||
return callback(std::move(out));
|
return callback(std::move(out));
|
||||||
@ -4899,9 +4898,9 @@ bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto is_invalid_value = false;
|
auto is_invalid_value = false;
|
||||||
auto len = get_header_value_u64(
|
auto len = get_header_value_u64(x.headers, "Content-Length",
|
||||||
x.headers, "Content-Length",
|
(std::numeric_limits<size_t>::max)(),
|
||||||
(std::numeric_limits<uint64_t>::max)(), 0, is_invalid_value);
|
0, is_invalid_value);
|
||||||
|
|
||||||
if (is_invalid_value) {
|
if (is_invalid_value) {
|
||||||
ret = false;
|
ret = false;
|
||||||
@ -7568,13 +7567,13 @@ inline bool Server::read_content_core(
|
|||||||
}
|
}
|
||||||
|
|
||||||
multipart_form_data_parser.set_boundary(std::move(boundary));
|
multipart_form_data_parser.set_boundary(std::move(boundary));
|
||||||
out = [&](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) {
|
out = [&](const char *buf, size_t n, size_t /*off*/, size_t /*len*/) {
|
||||||
return multipart_form_data_parser.parse(buf, n, multipart_header,
|
return multipart_form_data_parser.parse(buf, n, multipart_header,
|
||||||
multipart_receiver);
|
multipart_receiver);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
out = [receiver](const char *buf, size_t n, uint64_t /*off*/,
|
out = [receiver](const char *buf, size_t n, size_t /*off*/,
|
||||||
uint64_t /*len*/) { return receiver(buf, n); };
|
size_t /*len*/) { return receiver(buf, n); };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method == "DELETE" && !req.has_header("Content-Length")) {
|
if (req.method == "DELETE" && !req.has_header("Content-Length")) {
|
||||||
@ -9093,21 +9092,21 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
|
|||||||
auto out =
|
auto out =
|
||||||
req.content_receiver
|
req.content_receiver
|
||||||
? static_cast<ContentReceiverWithProgress>(
|
? static_cast<ContentReceiverWithProgress>(
|
||||||
[&](const char *buf, size_t n, uint64_t off, uint64_t len) {
|
[&](const char *buf, size_t n, size_t off, size_t len) {
|
||||||
if (redirect) { return true; }
|
if (redirect) { return true; }
|
||||||
auto ret = req.content_receiver(buf, n, off, len);
|
auto ret = req.content_receiver(buf, n, off, len);
|
||||||
if (!ret) { error = Error::Canceled; }
|
if (!ret) { error = Error::Canceled; }
|
||||||
return ret;
|
return ret;
|
||||||
})
|
})
|
||||||
: static_cast<ContentReceiverWithProgress>(
|
: static_cast<ContentReceiverWithProgress>(
|
||||||
[&](const char *buf, size_t n, uint64_t /*off*/,
|
[&](const char *buf, size_t n, size_t /*off*/,
|
||||||
uint64_t /*len*/) {
|
size_t /*len*/) {
|
||||||
assert(res.body.size() + n <= res.body.max_size());
|
assert(res.body.size() + n <= res.body.max_size());
|
||||||
res.body.append(buf, n);
|
res.body.append(buf, n);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto progress = [&](uint64_t current, uint64_t total) {
|
auto progress = [&](size_t current, size_t total) {
|
||||||
if (!req.download_progress || redirect) { return true; }
|
if (!req.download_progress || redirect) { return true; }
|
||||||
auto ret = req.download_progress(current, total);
|
auto ret = req.download_progress(current, total);
|
||||||
if (!ret) { error = Error::Canceled; }
|
if (!ret) { error = Error::Canceled; }
|
||||||
@ -9258,7 +9257,7 @@ inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
|
|||||||
req.response_handler = std::move(response_handler);
|
req.response_handler = std::move(response_handler);
|
||||||
req.content_receiver =
|
req.content_receiver =
|
||||||
[content_receiver](const char *data, size_t data_length,
|
[content_receiver](const char *data, size_t data_length,
|
||||||
uint64_t /*offset*/, uint64_t /*total_length*/) {
|
size_t /*offset*/, size_t /*total_length*/) {
|
||||||
return content_receiver(data, data_length);
|
return content_receiver(data, data_length);
|
||||||
};
|
};
|
||||||
req.download_progress = std::move(progress);
|
req.download_progress = std::move(progress);
|
||||||
@ -9448,7 +9447,7 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
|
|||||||
req.body = body;
|
req.body = body;
|
||||||
req.content_receiver =
|
req.content_receiver =
|
||||||
[content_receiver](const char *data, size_t data_length,
|
[content_receiver](const char *data, size_t data_length,
|
||||||
uint64_t /*offset*/, uint64_t /*total_length*/) {
|
size_t /*offset*/, size_t /*total_length*/) {
|
||||||
return content_receiver(data, data_length);
|
return content_receiver(data, data_length);
|
||||||
};
|
};
|
||||||
req.download_progress = std::move(progress);
|
req.download_progress = std::move(progress);
|
||||||
@ -9600,7 +9599,7 @@ inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
|
|||||||
req.body = body;
|
req.body = body;
|
||||||
req.content_receiver =
|
req.content_receiver =
|
||||||
[content_receiver](const char *data, size_t data_length,
|
[content_receiver](const char *data, size_t data_length,
|
||||||
uint64_t /*offset*/, uint64_t /*total_length*/) {
|
size_t /*offset*/, size_t /*total_length*/) {
|
||||||
return content_receiver(data, data_length);
|
return content_receiver(data, data_length);
|
||||||
};
|
};
|
||||||
req.download_progress = std::move(progress);
|
req.download_progress = std::move(progress);
|
||||||
@ -9755,7 +9754,7 @@ inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
|
|||||||
req.body = body;
|
req.body = body;
|
||||||
req.content_receiver =
|
req.content_receiver =
|
||||||
[content_receiver](const char *data, size_t data_length,
|
[content_receiver](const char *data, size_t data_length,
|
||||||
uint64_t /*offset*/, uint64_t /*total_length*/) {
|
size_t /*offset*/, size_t /*total_length*/) {
|
||||||
return content_receiver(data, data_length);
|
return content_receiver(data, data_length);
|
||||||
};
|
};
|
||||||
req.download_progress = std::move(progress);
|
req.download_progress = std::move(progress);
|
||||||
|
Reference in New Issue
Block a user