Skip to content

Commit b5b2a1d

Browse files
committed
Change uint64_t to size_t
1 parent 17ba303 commit b5b2a1d

File tree

1 file changed

+50
-51
lines changed

1 file changed

+50
-51
lines changed

httplib.h

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ using Headers =
577577
using Params = std::multimap<std::string, std::string>;
578578
using Match = std::smatch;
579579

580-
using DownloadProgress = std::function<bool(uint64_t current, uint64_t total)>;
581-
using UploadProgress = std::function<bool(uint64_t current, uint64_t total)>;
580+
using DownloadProgress = std::function<bool(size_t current, size_t total)>;
581+
using UploadProgress = std::function<bool(size_t current, size_t total)>;
582582

583583
struct Response;
584584
using ResponseHandler = std::function<bool(const Response &response)>;
@@ -674,9 +674,8 @@ struct FormDataProvider {
674674
};
675675
using FormDataProviderItems = std::vector<FormDataProvider>;
676676

677-
using ContentReceiverWithProgress =
678-
std::function<bool(const char *data, size_t data_length, uint64_t offset,
679-
uint64_t total_length)>;
677+
using ContentReceiverWithProgress = std::function<bool(
678+
const char *data, size_t data_length, size_t offset, size_t total_length)>;
680679

681680
using ContentReceiver =
682681
std::function<bool(const char *data, size_t data_length)>;
@@ -744,8 +743,8 @@ struct Request {
744743
bool has_header(const std::string &key) const;
745744
std::string get_header_value(const std::string &key, const char *def = "",
746745
size_t id = 0) const;
747-
uint64_t get_header_value_u64(const std::string &key, uint64_t def = 0,
748-
size_t id = 0) const;
746+
size_t get_header_value_u64(const std::string &key, size_t def = 0,
747+
size_t id = 0) const;
749748
size_t get_header_value_count(const std::string &key) const;
750749
void set_header(const std::string &key, const std::string &val);
751750

@@ -781,8 +780,8 @@ struct Response {
781780
bool has_header(const std::string &key) const;
782781
std::string get_header_value(const std::string &key, const char *def = "",
783782
size_t id = 0) const;
784-
uint64_t get_header_value_u64(const std::string &key, uint64_t def = 0,
785-
size_t id = 0) const;
783+
size_t get_header_value_u64(const std::string &key, size_t def = 0,
784+
size_t id = 0) const;
786785
size_t get_header_value_count(const std::string &key) const;
787786
void set_header(const std::string &key, const std::string &val);
788787

@@ -1334,8 +1333,8 @@ class Result {
13341333
std::string get_request_header_value(const std::string &key,
13351334
const char *def = "",
13361335
size_t id = 0) const;
1337-
uint64_t get_request_header_value_u64(const std::string &key,
1338-
uint64_t def = 0, size_t id = 0) const;
1336+
size_t get_request_header_value_u64(const std::string &key, size_t def = 0,
1337+
size_t id = 0) const;
13391338
size_t get_request_header_value_count(const std::string &key) const;
13401339

13411340
private:
@@ -2010,9 +2009,9 @@ inline bool is_numeric(const std::string &str) {
20102009
[](unsigned char c) { return std::isdigit(c); });
20112010
}
20122011

2013-
inline uint64_t get_header_value_u64(const Headers &headers,
2014-
const std::string &key, uint64_t def,
2015-
size_t id, bool &is_invalid_value) {
2012+
inline size_t get_header_value_u64(const Headers &headers,
2013+
const std::string &key, size_t def,
2014+
size_t id, bool &is_invalid_value) {
20162015
is_invalid_value = false;
20172016
auto rng = headers.equal_range(key);
20182017
auto it = rng.first;
@@ -2027,22 +2026,22 @@ inline uint64_t get_header_value_u64(const Headers &headers,
20272026
return def;
20282027
}
20292028

2030-
inline uint64_t get_header_value_u64(const Headers &headers,
2031-
const std::string &key, uint64_t def,
2032-
size_t id) {
2029+
inline size_t get_header_value_u64(const Headers &headers,
2030+
const std::string &key, size_t def,
2031+
size_t id) {
20332032
bool dummy = false;
20342033
return get_header_value_u64(headers, key, def, id, dummy);
20352034
}
20362035

20372036
} // namespace detail
20382037

2039-
inline uint64_t Request::get_header_value_u64(const std::string &key,
2040-
uint64_t def, size_t id) const {
2038+
inline size_t Request::get_header_value_u64(const std::string &key, size_t def,
2039+
size_t id) const {
20412040
return detail::get_header_value_u64(headers, key, def, id);
20422041
}
20432042

2044-
inline uint64_t Response::get_header_value_u64(const std::string &key,
2045-
uint64_t def, size_t id) const {
2043+
inline size_t Response::get_header_value_u64(const std::string &key, size_t def,
2044+
size_t id) const {
20462045
return detail::get_header_value_u64(headers, key, def, id);
20472046
}
20482047

@@ -2228,9 +2227,9 @@ inline std::ostream &operator<<(std::ostream &os, const Error &obj) {
22282227
return os;
22292228
}
22302229

2231-
inline uint64_t Result::get_request_header_value_u64(const std::string &key,
2232-
uint64_t def,
2233-
size_t id) const {
2230+
inline size_t Result::get_request_header_value_u64(const std::string &key,
2231+
size_t def,
2232+
size_t id) const {
22342233
return detail::get_header_value_u64(request_headers_, key, def, id);
22352234
}
22362235

@@ -4617,19 +4616,19 @@ inline bool read_headers(Stream &strm, Headers &headers) {
46174616
return true;
46184617
}
46194618

4620-
inline bool read_content_with_length(Stream &strm, uint64_t len,
4619+
inline bool read_content_with_length(Stream &strm, size_t len,
46214620
DownloadProgress progress,
46224621
ContentReceiverWithProgress out) {
46234622
char buf[CPPHTTPLIB_RECV_BUFSIZ];
46244623

4625-
uint64_t r = 0;
4624+
size_t r = 0;
46264625
while (r < len) {
46274626
auto read_len = static_cast<size_t>(len - r);
46284627
auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));
46294628
if (n <= 0) { return false; }
46304629

46314630
if (!out(buf, static_cast<size_t>(n), r, len)) { return false; }
4632-
r += static_cast<uint64_t>(n);
4631+
r += static_cast<size_t>(n);
46334632

46344633
if (progress) {
46354634
if (!progress(r, len)) { return false; }
@@ -4639,14 +4638,14 @@ inline bool read_content_with_length(Stream &strm, uint64_t len,
46394638
return true;
46404639
}
46414640

4642-
inline void skip_content_with_length(Stream &strm, uint64_t len) {
4641+
inline void skip_content_with_length(Stream &strm, size_t len) {
46434642
char buf[CPPHTTPLIB_RECV_BUFSIZ];
4644-
uint64_t r = 0;
4643+
size_t r = 0;
46454644
while (r < len) {
46464645
auto read_len = static_cast<size_t>(len - r);
46474646
auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ));
46484647
if (n <= 0) { return; }
4649-
r += static_cast<uint64_t>(n);
4648+
r += static_cast<size_t>(n);
46504649
}
46514650
}
46524651

@@ -4660,22 +4659,22 @@ inline ReadContentResult
46604659
read_content_without_length(Stream &strm, size_t payload_max_length,
46614660
ContentReceiverWithProgress out) {
46624661
char buf[CPPHTTPLIB_RECV_BUFSIZ];
4663-
uint64_t r = 0;
4662+
size_t r = 0;
46644663
for (;;) {
46654664
auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ);
46664665
if (n == 0) { return ReadContentResult::Success; }
46674666
if (n < 0) { return ReadContentResult::Error; }
46684667

46694668
// Check if adding this data would exceed the payload limit
46704669
if (r > payload_max_length ||
4671-
payload_max_length - r < static_cast<uint64_t>(n)) {
4670+
payload_max_length - r < static_cast<size_t>(n)) {
46724671
return ReadContentResult::PayloadTooLarge;
46734672
}
46744673

46754674
if (!out(buf, static_cast<size_t>(n), r, 0)) {
46764675
return ReadContentResult::Error;
46774676
}
4678-
r += static_cast<uint64_t>(n);
4677+
r += static_cast<size_t>(n);
46794678
}
46804679

46814680
return ReadContentResult::Success;
@@ -4693,7 +4692,7 @@ inline ReadContentResult read_content_chunked(Stream &strm, T &x,
46934692
if (!line_reader.getline()) { return ReadContentResult::Error; }
46944693

46954694
unsigned long chunk_len;
4696-
uint64_t total_len = 0;
4695+
size_t total_len = 0;
46974696
while (true) {
46984697
char *end_ptr;
46994698

@@ -4845,7 +4844,7 @@ bool prepare_content_receiver(T &x, int &status,
48454844
if (decompressor) {
48464845
if (decompressor->is_valid()) {
48474846
ContentReceiverWithProgress out = [&](const char *buf, size_t n,
4848-
uint64_t off, uint64_t len) {
4847+
size_t off, size_t len) {
48494848
return decompressor->decompress(buf, n,
48504849
[&](const char *buf2, size_t n2) {
48514850
return receiver(buf2, n2, off, len);
@@ -4859,8 +4858,8 @@ bool prepare_content_receiver(T &x, int &status,
48594858
}
48604859
}
48614860

4862-
ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off,
4863-
uint64_t len) {
4861+
ContentReceiverWithProgress out = [&](const char *buf, size_t n, size_t off,
4862+
size_t len) {
48644863
return receiver(buf, n, off, len);
48654864
};
48664865
return callback(std::move(out));
@@ -4899,9 +4898,9 @@ bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,
48994898
}
49004899
} else {
49014900
auto is_invalid_value = false;
4902-
auto len = get_header_value_u64(
4903-
x.headers, "Content-Length",
4904-
(std::numeric_limits<uint64_t>::max)(), 0, is_invalid_value);
4901+
auto len = get_header_value_u64(x.headers, "Content-Length",
4902+
(std::numeric_limits<size_t>::max)(),
4903+
0, is_invalid_value);
49054904

49064905
if (is_invalid_value) {
49074906
ret = false;
@@ -7568,13 +7567,13 @@ inline bool Server::read_content_core(
75687567
}
75697568

75707569
multipart_form_data_parser.set_boundary(std::move(boundary));
7571-
out = [&](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) {
7570+
out = [&](const char *buf, size_t n, size_t /*off*/, size_t /*len*/) {
75727571
return multipart_form_data_parser.parse(buf, n, multipart_header,
75737572
multipart_receiver);
75747573
};
75757574
} else {
7576-
out = [receiver](const char *buf, size_t n, uint64_t /*off*/,
7577-
uint64_t /*len*/) { return receiver(buf, n); };
7575+
out = [receiver](const char *buf, size_t n, size_t /*off*/,
7576+
size_t /*len*/) { return receiver(buf, n); };
75787577
}
75797578

75807579
if (req.method == "DELETE" && !req.has_header("Content-Length")) {
@@ -9093,21 +9092,21 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
90939092
auto out =
90949093
req.content_receiver
90959094
? static_cast<ContentReceiverWithProgress>(
9096-
[&](const char *buf, size_t n, uint64_t off, uint64_t len) {
9095+
[&](const char *buf, size_t n, size_t off, size_t len) {
90979096
if (redirect) { return true; }
90989097
auto ret = req.content_receiver(buf, n, off, len);
90999098
if (!ret) { error = Error::Canceled; }
91009099
return ret;
91019100
})
91029101
: static_cast<ContentReceiverWithProgress>(
9103-
[&](const char *buf, size_t n, uint64_t /*off*/,
9104-
uint64_t /*len*/) {
9102+
[&](const char *buf, size_t n, size_t /*off*/,
9103+
size_t /*len*/) {
91059104
assert(res.body.size() + n <= res.body.max_size());
91069105
res.body.append(buf, n);
91079106
return true;
91089107
});
91099108

9110-
auto progress = [&](uint64_t current, uint64_t total) {
9109+
auto progress = [&](size_t current, size_t total) {
91119110
if (!req.download_progress || redirect) { return true; }
91129111
auto ret = req.download_progress(current, total);
91139112
if (!ret) { error = Error::Canceled; }
@@ -9258,7 +9257,7 @@ inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
92589257
req.response_handler = std::move(response_handler);
92599258
req.content_receiver =
92609259
[content_receiver](const char *data, size_t data_length,
9261-
uint64_t /*offset*/, uint64_t /*total_length*/) {
9260+
size_t /*offset*/, size_t /*total_length*/) {
92629261
return content_receiver(data, data_length);
92639262
};
92649263
req.download_progress = std::move(progress);
@@ -9448,7 +9447,7 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
94489447
req.body = body;
94499448
req.content_receiver =
94509449
[content_receiver](const char *data, size_t data_length,
9451-
uint64_t /*offset*/, uint64_t /*total_length*/) {
9450+
size_t /*offset*/, size_t /*total_length*/) {
94529451
return content_receiver(data, data_length);
94539452
};
94549453
req.download_progress = std::move(progress);
@@ -9600,7 +9599,7 @@ inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
96009599
req.body = body;
96019600
req.content_receiver =
96029601
[content_receiver](const char *data, size_t data_length,
9603-
uint64_t /*offset*/, uint64_t /*total_length*/) {
9602+
size_t /*offset*/, size_t /*total_length*/) {
96049603
return content_receiver(data, data_length);
96059604
};
96069605
req.download_progress = std::move(progress);
@@ -9755,7 +9754,7 @@ inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
97559754
req.body = body;
97569755
req.content_receiver =
97579756
[content_receiver](const char *data, size_t data_length,
9758-
uint64_t /*offset*/, uint64_t /*total_length*/) {
9757+
size_t /*offset*/, size_t /*total_length*/) {
97599758
return content_receiver(data, data_length);
97609759
};
97619760
req.download_progress = std::move(progress);

0 commit comments

Comments
 (0)