@@ -1060,7 +1060,7 @@ inline void read_file(const std::string &path, std::string &out) {
1060
1060
1061
1061
inline std::string file_extension (const std::string &path) {
1062
1062
std::smatch m;
1063
- auto re = std::regex (" \\ .([a-zA-Z0-9]+)$" );
1063
+ static auto re = std::regex (" \\ .([a-zA-Z0-9]+)$" );
1064
1064
if (std::regex_search (path, m, re)) { return m[1 ].str (); }
1065
1065
return std::string ();
1066
1066
}
@@ -2823,7 +2823,7 @@ inline void Server::stop() {
2823
2823
}
2824
2824
2825
2825
inline bool Server::parse_request_line (const char *s, Request &req) {
2826
- static std::regex re (
2826
+ const static std::regex re (
2827
2827
" (GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI) "
2828
2828
" (([^?]+)(?:\\ ?(.*?))?) (HTTP/1\\ .[01])\r\n " );
2829
2829
@@ -3487,52 +3487,49 @@ inline bool Client::redirect(const Request &req, Response &res) {
3487
3487
auto location = res.get_header_value (" location" );
3488
3488
if (location.empty ()) { return false ; }
3489
3489
3490
- std::regex re (
3490
+ const static std::regex re (
3491
3491
R"( ^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*(?:\?[^#]*)?)(?:#.*)?)" );
3492
3492
3493
3493
std::smatch m;
3494
- if (regex_match (location, m, re)) {
3495
- auto next_scheme = m[1 ].str ();
3496
- auto next_host = m[2 ].str ();
3497
- auto next_path = m[3 ].str ();
3498
- if (next_host.empty ()) { next_host = host_; }
3499
- if (next_path.empty ()) { next_path = " /" ; }
3494
+ if (!regex_match (location, m, re)) { return false ; }
3500
3495
3501
- auto scheme = is_ssl () ? " https" : " http" ;
3496
+ auto next_scheme = m[1 ].str ();
3497
+ auto next_host = m[2 ].str ();
3498
+ auto next_path = m[3 ].str ();
3499
+ if (next_host.empty ()) { next_host = host_; }
3500
+ if (next_path.empty ()) { next_path = " /" ; }
3502
3501
3503
- if (next_scheme == scheme && next_host == host_) {
3504
- return detail::redirect (*this , req, res, next_path);
3505
- } else {
3506
- if (next_scheme == " https" ) {
3502
+ auto scheme = is_ssl () ? " https" : " http" ;
3503
+
3504
+ if (next_scheme == scheme && next_host == host_) {
3505
+ return detail::redirect (*this , req, res, next_path);
3506
+ } else {
3507
+ if (next_scheme == " https" ) {
3507
3508
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3508
- SSLClient cli (next_host.c_str ());
3509
- cli.set_follow_location (true );
3510
- return detail::redirect (cli, req, res, next_path);
3509
+ SSLClient cli (next_host.c_str ());
3510
+ cli.set_follow_location (true );
3511
+ return detail::redirect (cli, req, res, next_path);
3511
3512
#else
3512
- return false ;
3513
+ return false ;
3513
3514
#endif
3514
- } else {
3515
- Client cli (next_host.c_str ());
3516
- cli.set_follow_location (true );
3517
- return detail::redirect (cli, req, res, next_path);
3518
- }
3515
+ } else {
3516
+ Client cli (next_host.c_str ());
3517
+ cli.set_follow_location (true );
3518
+ return detail::redirect (cli, req, res, next_path);
3519
3519
}
3520
3520
}
3521
- return false ;
3522
3521
}
3523
3522
3524
3523
inline bool Client::write_request (Stream &strm, const Request &req,
3525
3524
bool last_connection) {
3526
3525
BufferStream bstrm;
3527
3526
3528
3527
// Request line
3529
- static std::regex re (
3528
+ const static std::regex re (
3530
3529
R"( ^([^:/?#]+://[^/?#]*)?([^?#]*(?:\?[^#]*)?(?:#.*)?))" );
3531
3530
3532
3531
std::smatch m;
3533
- if (!regex_match (req.path , m, re)) {
3534
- return false ;
3535
- }
3532
+ if (!regex_match (req.path , m, re)) { return false ; }
3536
3533
3537
3534
auto path = m[1 ].str () + detail::encode_url (m[2 ].str ());
3538
3535
@@ -3656,9 +3653,7 @@ inline bool Client::process_request(Stream &strm, const Request &req,
3656
3653
Response &res, bool last_connection,
3657
3654
bool &connection_close) {
3658
3655
// Send request
3659
- if (!write_request (strm, req, last_connection)) {
3660
- return false ;
3661
- }
3656
+ if (!write_request (strm, req, last_connection)) { return false ; }
3662
3657
3663
3658
// Receive response and headers
3664
3659
if (!read_response_line (strm, res) ||
@@ -4011,9 +4006,7 @@ inline void Client::set_follow_location(bool on) { follow_location_ = on; }
4011
4006
4012
4007
inline void Client::set_compress (bool on) { compress_ = on; }
4013
4008
4014
- inline void Client::set_interface (const char *intf) {
4015
- interface_ = intf;
4016
- }
4009
+ inline void Client::set_interface (const char *intf) { interface_ = intf; }
4017
4010
4018
4011
/*
4019
4012
* SSL Implementation
0 commit comments