Skip to content

Commit 87a5ae6

Browse files
committed
1 parent 33acccb commit 87a5ae6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

httplib.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ inline std::string decode_url(const std::string &s,
29512951

29522952
inline std::string file_extension(const std::string &path) {
29532953
std::smatch m;
2954-
static auto re = std::regex("\\.([a-zA-Z0-9]+)$");
2954+
thread_local auto re = std::regex("\\.([a-zA-Z0-9]+)$");
29552955
if (std::regex_search(path, m, re)) { return m[1].str(); }
29562956
return std::string();
29572957
}
@@ -5013,7 +5013,7 @@ class MultipartFormDataParser {
50135013
file_.content_type =
50145014
trim_copy(header.substr(str_len(header_content_type)));
50155015
} else {
5016-
static const std::regex re_content_disposition(
5016+
thread_local const std::regex re_content_disposition(
50175017
R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~",
50185018
std::regex_constants::icase);
50195019

@@ -5036,7 +5036,7 @@ class MultipartFormDataParser {
50365036
it = params.find("filename*");
50375037
if (it != params.end()) {
50385038
// Only allow UTF-8 encoding...
5039-
static const std::regex re_rfc5987_encoding(
5039+
thread_local const std::regex re_rfc5987_encoding(
50405040
R"~(^UTF-8''(.+?)$)~", std::regex_constants::icase);
50415041

50425042
std::smatch m2;
@@ -5201,7 +5201,7 @@ inline std::string random_string(size_t length) {
52015201
constexpr const char data[] =
52025202
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
52035203

5204-
static thread_local std::mt19937 engine([]() {
5204+
thread_local auto engine([]() {
52055205
// std::random_device might actually be deterministic on some
52065206
// platforms, but due to lack of support in the c++ standard library,
52075207
// doing better requires either some ugly hacks or breaking portability.
@@ -5723,7 +5723,7 @@ inline bool parse_www_authenticate(const Response &res,
57235723
bool is_proxy) {
57245724
auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
57255725
if (res.has_header(auth_key)) {
5726-
static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~");
5726+
thread_local auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~");
57275727
auto s = res.get_header_value(auth_key);
57285728
auto pos = s.find(' ');
57295729
if (pos != std::string::npos) {
@@ -5807,7 +5807,7 @@ inline void hosted_at(const std::string &hostname,
58075807
inline std::string append_query_params(const std::string &path,
58085808
const Params &params) {
58095809
std::string path_with_query = path;
5810-
const static std::regex re("[^?]+\\?.*");
5810+
thread_local const std::regex re("[^?]+\\?.*");
58115811
auto delm = std::regex_match(path, re) ? '&' : '?';
58125812
path_with_query += delm + detail::params_to_query_str(params);
58135813
return path_with_query;
@@ -6581,7 +6581,7 @@ inline bool Server::parse_request_line(const char *s, Request &req) const {
65816581
if (count != 3) { return false; }
65826582
}
65836583

6584-
static const std::set<std::string> methods{
6584+
thread_local const std::set<std::string> methods{
65856585
"GET", "HEAD", "POST", "PUT", "DELETE",
65866586
"CONNECT", "OPTIONS", "TRACE", "PATCH", "PRI"};
65876587

@@ -7581,9 +7581,9 @@ inline bool ClientImpl::read_response_line(Stream &strm, const Request &req,
75817581
if (!line_reader.getline()) { return false; }
75827582

75837583
#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
7584-
const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n");
7584+
thread_local const std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n");
75857585
#else
7586-
const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
7586+
thread_local const std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
75877587
#endif
75887588

75897589
std::cmatch m;
@@ -7815,7 +7815,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
78157815
auto location = res.get_header_value("location");
78167816
if (location.empty()) { return false; }
78177817

7818-
const static std::regex re(
7818+
thread_local const std::regex re(
78197819
R"((?:(https?):)?(?://(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)");
78207820

78217821
std::smatch m;

0 commit comments

Comments
 (0)