|
8 | 8 | #ifndef CPPHTTPLIB_HTTPLIB_H |
9 | 9 | #define CPPHTTPLIB_HTTPLIB_H |
10 | 10 |
|
11 | | -#define CPPHTTPLIB_VERSION "0.14.3" |
| 11 | +#define CPPHTTPLIB_VERSION "0.15.0" |
12 | 12 |
|
13 | 13 | /* |
14 | 14 | * Configuration |
@@ -4637,28 +4637,31 @@ inline std::string to_lower(const char *beg, const char *end) { |
4637 | 4637 | return out; |
4638 | 4638 | } |
4639 | 4639 |
|
4640 | | -inline std::string make_multipart_data_boundary() { |
| 4640 | +inline std::string random_string(size_t length) { |
4641 | 4641 | static const char data[] = |
4642 | 4642 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
4643 | 4643 |
|
4644 | 4644 | // std::random_device might actually be deterministic on some |
4645 | 4645 | // platforms, but due to lack of support in the c++ standard library, |
4646 | 4646 | // doing better requires either some ugly hacks or breaking portability. |
4647 | | - std::random_device seed_gen; |
| 4647 | + static std::random_device seed_gen; |
4648 | 4648 |
|
4649 | 4649 | // Request 128 bits of entropy for initialization |
4650 | | - std::seed_seq seed_sequence{seed_gen(), seed_gen(), seed_gen(), seed_gen()}; |
4651 | | - std::mt19937 engine(seed_sequence); |
| 4650 | + static std::seed_seq seed_sequence{seed_gen(), seed_gen(), seed_gen(), seed_gen()}; |
4652 | 4651 |
|
4653 | | - std::string result = "--cpp-httplib-multipart-data-"; |
| 4652 | + static std::mt19937 engine(seed_sequence); |
4654 | 4653 |
|
4655 | | - for (auto i = 0; i < 16; i++) { |
| 4654 | + std::string result; |
| 4655 | + for (size_t i = 0; i < length; i++) { |
4656 | 4656 | result += data[engine() % (sizeof(data) - 1)]; |
4657 | 4657 | } |
4658 | | - |
4659 | 4658 | return result; |
4660 | 4659 | } |
4661 | 4660 |
|
| 4661 | +inline std::string make_multipart_data_boundary() { |
| 4662 | + return "--cpp-httplib-multipart-data-" + detail::random_string(16); |
| 4663 | +} |
| 4664 | + |
4662 | 4665 | inline bool is_multipart_boundary_chars_valid(const std::string &boundary) { |
4663 | 4666 | auto valid = true; |
4664 | 4667 | for (size_t i = 0; i < boundary.size(); i++) { |
@@ -5133,20 +5136,6 @@ inline bool parse_www_authenticate(const Response &res, |
5133 | 5136 | return false; |
5134 | 5137 | } |
5135 | 5138 |
|
5136 | | -// https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c/440240#answer-440240 |
5137 | | -inline std::string random_string(size_t length) { |
5138 | | - auto randchar = []() -> char { |
5139 | | - const char charset[] = "0123456789" |
5140 | | - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
5141 | | - "abcdefghijklmnopqrstuvwxyz"; |
5142 | | - const size_t max_index = (sizeof(charset) - 1); |
5143 | | - return charset[static_cast<size_t>(std::rand()) % max_index]; |
5144 | | - }; |
5145 | | - std::string str(length, 0); |
5146 | | - std::generate_n(str.begin(), length, randchar); |
5147 | | - return str; |
5148 | | -} |
5149 | | - |
5150 | 5139 | class ContentProviderAdapter { |
5151 | 5140 | public: |
5152 | 5141 | explicit ContentProviderAdapter( |
|
0 commit comments