Skip to content

Commit 2ce7c22

Browse files
committed
Fix #1747
1 parent 4ef9ed8 commit 2ce7c22

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

httplib.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef CPPHTTPLIB_HTTPLIB_H
99
#define CPPHTTPLIB_HTTPLIB_H
1010

11-
#define CPPHTTPLIB_VERSION "0.14.3"
11+
#define CPPHTTPLIB_VERSION "0.15.0"
1212

1313
/*
1414
* Configuration
@@ -4637,28 +4637,31 @@ inline std::string to_lower(const char *beg, const char *end) {
46374637
return out;
46384638
}
46394639

4640-
inline std::string make_multipart_data_boundary() {
4640+
inline std::string random_string(size_t length) {
46414641
static const char data[] =
46424642
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
46434643

46444644
// std::random_device might actually be deterministic on some
46454645
// platforms, but due to lack of support in the c++ standard library,
46464646
// doing better requires either some ugly hacks or breaking portability.
4647-
std::random_device seed_gen;
4647+
static std::random_device seed_gen;
46484648

46494649
// 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()};
46524651

4653-
std::string result = "--cpp-httplib-multipart-data-";
4652+
static std::mt19937 engine(seed_sequence);
46544653

4655-
for (auto i = 0; i < 16; i++) {
4654+
std::string result;
4655+
for (size_t i = 0; i < length; i++) {
46564656
result += data[engine() % (sizeof(data) - 1)];
46574657
}
4658-
46594658
return result;
46604659
}
46614660

4661+
inline std::string make_multipart_data_boundary() {
4662+
return "--cpp-httplib-multipart-data-" + detail::random_string(16);
4663+
}
4664+
46624665
inline bool is_multipart_boundary_chars_valid(const std::string &boundary) {
46634666
auto valid = true;
46644667
for (size_t i = 0; i < boundary.size(); i++) {
@@ -5133,20 +5136,6 @@ inline bool parse_www_authenticate(const Response &res,
51335136
return false;
51345137
}
51355138

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-
51505139
class ContentProviderAdapter {
51515140
public:
51525141
explicit ContentProviderAdapter(

0 commit comments

Comments
 (0)