yhirose 9 months ago
parent
commit
87a5ae64a4
1 changed files with 10 additions and 10 deletions
  1. 10 10
      httplib.h

+ 10 - 10
httplib.h

@@ -2951,7 +2951,7 @@ inline std::string decode_url(const std::string &s,
 
 
 inline std::string file_extension(const std::string &path) {
 inline std::string file_extension(const std::string &path) {
   std::smatch m;
   std::smatch m;
-  static auto re = std::regex("\\.([a-zA-Z0-9]+)$");
+  thread_local auto re = std::regex("\\.([a-zA-Z0-9]+)$");
   if (std::regex_search(path, m, re)) { return m[1].str(); }
   if (std::regex_search(path, m, re)) { return m[1].str(); }
   return std::string();
   return std::string();
 }
 }
@@ -5013,7 +5013,7 @@ public:
             file_.content_type =
             file_.content_type =
                 trim_copy(header.substr(str_len(header_content_type)));
                 trim_copy(header.substr(str_len(header_content_type)));
           } else {
           } else {
-            static const std::regex re_content_disposition(
+            thread_local const std::regex re_content_disposition(
                 R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~",
                 R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~",
                 std::regex_constants::icase);
                 std::regex_constants::icase);
 
 
@@ -5036,7 +5036,7 @@ public:
               it = params.find("filename*");
               it = params.find("filename*");
               if (it != params.end()) {
               if (it != params.end()) {
                 // Only allow UTF-8 encoding...
                 // Only allow UTF-8 encoding...
-                static const std::regex re_rfc5987_encoding(
+                thread_local const std::regex re_rfc5987_encoding(
                     R"~(^UTF-8''(.+?)$)~", std::regex_constants::icase);
                     R"~(^UTF-8''(.+?)$)~", std::regex_constants::icase);
 
 
                 std::smatch m2;
                 std::smatch m2;
@@ -5201,7 +5201,7 @@ inline std::string random_string(size_t length) {
   constexpr const char data[] =
   constexpr const char data[] =
       "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
       "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
 
-  static thread_local std::mt19937 engine([]() {
+  thread_local auto engine([]() {
     // std::random_device might actually be deterministic on some
     // std::random_device might actually be deterministic on some
     // platforms, but due to lack of support in the c++ standard library,
     // platforms, but due to lack of support in the c++ standard library,
     // doing better requires either some ugly hacks or breaking portability.
     // doing better requires either some ugly hacks or breaking portability.
@@ -5723,7 +5723,7 @@ inline bool parse_www_authenticate(const Response &res,
                                    bool is_proxy) {
                                    bool is_proxy) {
   auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
   auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
   if (res.has_header(auth_key)) {
   if (res.has_header(auth_key)) {
-    static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~");
+    thread_local auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~");
     auto s = res.get_header_value(auth_key);
     auto s = res.get_header_value(auth_key);
     auto pos = s.find(' ');
     auto pos = s.find(' ');
     if (pos != std::string::npos) {
     if (pos != std::string::npos) {
@@ -5807,7 +5807,7 @@ inline void hosted_at(const std::string &hostname,
 inline std::string append_query_params(const std::string &path,
 inline std::string append_query_params(const std::string &path,
                                        const Params &params) {
                                        const Params &params) {
   std::string path_with_query = path;
   std::string path_with_query = path;
-  const static std::regex re("[^?]+\\?.*");
+  thread_local const std::regex re("[^?]+\\?.*");
   auto delm = std::regex_match(path, re) ? '&' : '?';
   auto delm = std::regex_match(path, re) ? '&' : '?';
   path_with_query += delm + detail::params_to_query_str(params);
   path_with_query += delm + detail::params_to_query_str(params);
   return path_with_query;
   return path_with_query;
@@ -6581,7 +6581,7 @@ inline bool Server::parse_request_line(const char *s, Request &req) const {
     if (count != 3) { return false; }
     if (count != 3) { return false; }
   }
   }
 
 
-  static const std::set<std::string> methods{
+  thread_local const std::set<std::string> methods{
       "GET",     "HEAD",    "POST",  "PUT",   "DELETE",
       "GET",     "HEAD",    "POST",  "PUT",   "DELETE",
       "CONNECT", "OPTIONS", "TRACE", "PATCH", "PRI"};
       "CONNECT", "OPTIONS", "TRACE", "PATCH", "PRI"};
 
 
@@ -7581,9 +7581,9 @@ inline bool ClientImpl::read_response_line(Stream &strm, const Request &req,
   if (!line_reader.getline()) { return false; }
   if (!line_reader.getline()) { return false; }
 
 
 #ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
 #ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
-  const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n");
+  thread_local const std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n");
 #else
 #else
-  const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
+  thread_local const  std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
 #endif
 #endif
 
 
   std::cmatch m;
   std::cmatch m;
@@ -7815,7 +7815,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
   auto location = res.get_header_value("location");
   auto location = res.get_header_value("location");
   if (location.empty()) { return false; }
   if (location.empty()) { return false; }
 
 
-  const static std::regex re(
+  thread_local const std::regex re(
       R"((?:(https?):)?(?://(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)");
       R"((?:(https?):)?(?://(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)");
 
 
   std::smatch m;
   std::smatch m;