diff --git a/httplib.h b/httplib.h index e6c5534..07310e4 100644 --- a/httplib.h +++ b/httplib.h @@ -577,8 +577,8 @@ using Headers = using Params = std::multimap; using Match = std::smatch; -using DownloadProgress = std::function; -using UploadProgress = std::function; +using DownloadProgress = std::function; +using UploadProgress = std::function; struct Response; using ResponseHandler = std::function; @@ -674,9 +674,8 @@ struct FormDataProvider { }; using FormDataProviderItems = std::vector; -using ContentReceiverWithProgress = - std::function; +using ContentReceiverWithProgress = std::function; using ContentReceiver = std::function; @@ -744,8 +743,8 @@ struct Request { bool has_header(const std::string &key) const; std::string get_header_value(const std::string &key, const char *def = "", size_t id = 0) const; - uint64_t get_header_value_u64(const std::string &key, uint64_t def = 0, - size_t id = 0) const; + size_t get_header_value_u64(const std::string &key, size_t def = 0, + size_t id = 0) const; size_t get_header_value_count(const std::string &key) const; void set_header(const std::string &key, const std::string &val); @@ -781,8 +780,8 @@ struct Response { bool has_header(const std::string &key) const; std::string get_header_value(const std::string &key, const char *def = "", size_t id = 0) const; - uint64_t get_header_value_u64(const std::string &key, uint64_t def = 0, - size_t id = 0) const; + size_t get_header_value_u64(const std::string &key, size_t def = 0, + size_t id = 0) const; size_t get_header_value_count(const std::string &key) const; 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, const char *def = "", size_t id = 0) const; - uint64_t get_request_header_value_u64(const std::string &key, - uint64_t def = 0, size_t id = 0) const; + size_t get_request_header_value_u64(const std::string &key, size_t def = 0, + size_t id = 0) const; size_t get_request_header_value_count(const std::string &key) const; private: @@ -2010,9 +2009,9 @@ inline bool is_numeric(const std::string &str) { [](unsigned char c) { return std::isdigit(c); }); } -inline uint64_t get_header_value_u64(const Headers &headers, - const std::string &key, uint64_t def, - size_t id, bool &is_invalid_value) { +inline size_t get_header_value_u64(const Headers &headers, + const std::string &key, size_t def, + size_t id, bool &is_invalid_value) { is_invalid_value = false; auto rng = headers.equal_range(key); auto it = rng.first; @@ -2027,22 +2026,22 @@ inline uint64_t get_header_value_u64(const Headers &headers, return def; } -inline uint64_t get_header_value_u64(const Headers &headers, - const std::string &key, uint64_t def, - size_t id) { +inline size_t get_header_value_u64(const Headers &headers, + const std::string &key, size_t def, + size_t id) { bool dummy = false; return get_header_value_u64(headers, key, def, id, dummy); } } // namespace detail -inline uint64_t Request::get_header_value_u64(const std::string &key, - uint64_t def, size_t id) const { +inline size_t Request::get_header_value_u64(const std::string &key, size_t def, + size_t id) const { return detail::get_header_value_u64(headers, key, def, id); } -inline uint64_t Response::get_header_value_u64(const std::string &key, - uint64_t def, size_t id) const { +inline size_t Response::get_header_value_u64(const std::string &key, size_t def, + size_t id) const { return detail::get_header_value_u64(headers, key, def, id); } @@ -2228,9 +2227,9 @@ inline std::ostream &operator<<(std::ostream &os, const Error &obj) { return os; } -inline uint64_t Result::get_request_header_value_u64(const std::string &key, - uint64_t def, - size_t id) const { +inline size_t Result::get_request_header_value_u64(const std::string &key, + size_t def, + size_t id) const { 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; } -inline bool read_content_with_length(Stream &strm, uint64_t len, +inline bool read_content_with_length(Stream &strm, size_t len, DownloadProgress progress, ContentReceiverWithProgress out) { char buf[CPPHTTPLIB_RECV_BUFSIZ]; - uint64_t r = 0; + size_t r = 0; while (r < len) { auto read_len = static_cast(len - r); auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ)); if (n <= 0) { return false; } if (!out(buf, static_cast(n), r, len)) { return false; } - r += static_cast(n); + r += static_cast(n); if (progress) { if (!progress(r, len)) { return false; } @@ -4639,14 +4638,14 @@ inline bool read_content_with_length(Stream &strm, uint64_t len, 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]; - uint64_t r = 0; + size_t r = 0; while (r < len) { auto read_len = static_cast(len - r); auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ)); if (n <= 0) { return; } - r += static_cast(n); + r += static_cast(n); } } @@ -4660,7 +4659,7 @@ inline ReadContentResult read_content_without_length(Stream &strm, size_t payload_max_length, ContentReceiverWithProgress out) { char buf[CPPHTTPLIB_RECV_BUFSIZ]; - uint64_t r = 0; + size_t r = 0; for (;;) { auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ); 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 if (r > payload_max_length || - payload_max_length - r < static_cast(n)) { + payload_max_length - r < static_cast(n)) { return ReadContentResult::PayloadTooLarge; } if (!out(buf, static_cast(n), r, 0)) { return ReadContentResult::Error; } - r += static_cast(n); + r += static_cast(n); } return ReadContentResult::Success; @@ -4693,7 +4692,7 @@ inline ReadContentResult read_content_chunked(Stream &strm, T &x, if (!line_reader.getline()) { return ReadContentResult::Error; } unsigned long chunk_len; - uint64_t total_len = 0; + size_t total_len = 0; while (true) { char *end_ptr; @@ -4845,7 +4844,7 @@ bool prepare_content_receiver(T &x, int &status, if (decompressor) { if (decompressor->is_valid()) { 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, [&](const char *buf2, size_t n2) { 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, - uint64_t len) { + ContentReceiverWithProgress out = [&](const char *buf, size_t n, size_t off, + size_t len) { return receiver(buf, n, off, len); }; return callback(std::move(out)); @@ -4899,9 +4898,9 @@ bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status, } } else { auto is_invalid_value = false; - auto len = get_header_value_u64( - x.headers, "Content-Length", - (std::numeric_limits::max)(), 0, is_invalid_value); + auto len = get_header_value_u64(x.headers, "Content-Length", + (std::numeric_limits::max)(), + 0, is_invalid_value); if (is_invalid_value) { ret = false; @@ -7568,13 +7567,13 @@ inline bool Server::read_content_core( } 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, multipart_receiver); }; } else { - out = [receiver](const char *buf, size_t n, uint64_t /*off*/, - uint64_t /*len*/) { return receiver(buf, n); }; + out = [receiver](const char *buf, size_t n, size_t /*off*/, + size_t /*len*/) { return receiver(buf, n); }; } if (req.method == "DELETE" && !req.has_header("Content-Length")) { @@ -9093,21 +9092,21 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req, auto out = req.content_receiver ? static_cast( - [&](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; } auto ret = req.content_receiver(buf, n, off, len); if (!ret) { error = Error::Canceled; } return ret; }) : static_cast( - [&](const char *buf, size_t n, uint64_t /*off*/, - uint64_t /*len*/) { + [&](const char *buf, size_t n, size_t /*off*/, + size_t /*len*/) { assert(res.body.size() + n <= res.body.max_size()); res.body.append(buf, n); 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; } auto ret = req.download_progress(current, total); 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.content_receiver = [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); }; 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.content_receiver = [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); }; 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.content_receiver = [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); }; 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.content_receiver = [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); }; req.download_progress = std::move(progress);