|
11 | 11 | /*
|
12 | 12 | * Configuration
|
13 | 13 | */
|
| 14 | + |
14 | 15 | #ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
|
15 | 16 | #define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
|
16 | 17 | #endif
|
|
60 | 61 | #define _CRT_NONSTDC_NO_DEPRECATE
|
61 | 62 | #endif //_CRT_NONSTDC_NO_DEPRECATE
|
62 | 63 |
|
| 64 | +/* |
| 65 | + * Headers |
| 66 | + */ |
| 67 | + |
63 | 68 | #if defined(_MSC_VER)
|
64 | 69 | #ifdef _WIN64
|
65 | 70 | typedef __int64 ssize_t;
|
@@ -162,6 +167,9 @@ inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1) {
|
162 | 167 | #include <zlib.h>
|
163 | 168 | #endif
|
164 | 169 |
|
| 170 | +/* |
| 171 | + * Declaration |
| 172 | + */ |
165 | 173 | namespace httplib {
|
166 | 174 |
|
167 | 175 | namespace detail {
|
@@ -742,7 +750,7 @@ class SSLClient : public Client {
|
742 | 750 |
|
743 | 751 | long get_openssl_verify_result() const;
|
744 | 752 |
|
745 |
| - SSL_CTX* ssl_context() const noexcept; |
| 753 | + SSL_CTX *ssl_context() const noexcept; |
746 | 754 |
|
747 | 755 | private:
|
748 | 756 | virtual bool process_and_close_socket(
|
@@ -770,6 +778,7 @@ class SSLClient : public Client {
|
770 | 778 | /*
|
771 | 779 | * Implementation
|
772 | 780 | */
|
| 781 | + |
773 | 782 | namespace detail {
|
774 | 783 |
|
775 | 784 | inline bool is_hex(char c, int &v) {
|
@@ -1066,7 +1075,8 @@ inline bool wait_until_socket_is_ready(socket_t sock, time_t sec, time_t usec) {
|
1066 | 1075 | pfd_read.revents & (POLLIN | POLLOUT)) {
|
1067 | 1076 | int error = 0;
|
1068 | 1077 | socklen_t len = sizeof(error);
|
1069 |
| - return getsockopt(sock, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&error), &len) >= 0 && |
| 1078 | + return getsockopt(sock, SOL_SOCKET, SO_ERROR, |
| 1079 | + reinterpret_cast<char *>(&error), &len) >= 0 && |
1070 | 1080 | !error;
|
1071 | 1081 | }
|
1072 | 1082 | return false;
|
@@ -1177,9 +1187,11 @@ socket_t create_socket(const char *host, int port, Fn fn,
|
1177 | 1187 |
|
1178 | 1188 | // Make 'reuse address' option available
|
1179 | 1189 | int yes = 1;
|
1180 |
| - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&yes), sizeof(yes)); |
| 1190 | + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char *>(&yes), |
| 1191 | + sizeof(yes)); |
1181 | 1192 | #ifdef SO_REUSEPORT
|
1182 |
| - setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<char*>(&yes), sizeof(yes)); |
| 1193 | + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<char *>(&yes), |
| 1194 | + sizeof(yes)); |
1183 | 1195 | #endif
|
1184 | 1196 |
|
1185 | 1197 | // bind or connect
|
@@ -1221,8 +1233,8 @@ inline std::string get_remote_addr(socket_t sock) {
|
1221 | 1233 | if (!getpeername(sock, reinterpret_cast<struct sockaddr *>(&addr), &len)) {
|
1222 | 1234 | char ipstr[NI_MAXHOST];
|
1223 | 1235 |
|
1224 |
| - if (!getnameinfo(reinterpret_cast<struct sockaddr *>(&addr), len, ipstr, sizeof(ipstr), |
1225 |
| - nullptr, 0, NI_NUMERICHOST)) { |
| 1236 | + if (!getnameinfo(reinterpret_cast<struct sockaddr *>(&addr), len, ipstr, |
| 1237 | + sizeof(ipstr), nullptr, 0, NI_NUMERICHOST)) { |
1226 | 1238 | return ipstr;
|
1227 | 1239 | }
|
1228 | 1240 | }
|
@@ -1303,15 +1315,16 @@ inline bool compress(std::string &content) {
|
1303 | 1315 | if (ret != Z_OK) { return false; }
|
1304 | 1316 |
|
1305 | 1317 | strm.avail_in = content.size();
|
1306 |
| - strm.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(content.data())); |
| 1318 | + strm.next_in = |
| 1319 | + const_cast<Bytef *>(reinterpret_cast<const Bytef *>(content.data())); |
1307 | 1320 |
|
1308 | 1321 | std::string compressed;
|
1309 | 1322 |
|
1310 | 1323 | const auto bufsiz = 16384;
|
1311 | 1324 | char buff[bufsiz];
|
1312 | 1325 | do {
|
1313 | 1326 | strm.avail_out = bufsiz;
|
1314 |
| - strm.next_out = reinterpret_cast<Bytef*>(buff); |
| 1327 | + strm.next_out = reinterpret_cast<Bytef *>(buff); |
1315 | 1328 | ret = deflate(&strm, Z_FINISH);
|
1316 | 1329 | assert(ret != Z_STREAM_ERROR);
|
1317 | 1330 | compressed.append(buff, bufsiz - strm.avail_out);
|
@@ -1348,13 +1361,13 @@ class decompressor {
|
1348 | 1361 | int ret = Z_OK;
|
1349 | 1362 |
|
1350 | 1363 | strm.avail_in = data_length;
|
1351 |
| - strm.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef *>(data)); |
| 1364 | + strm.next_in = const_cast<Bytef *>(reinterpret_cast<const Bytef *>(data)); |
1352 | 1365 |
|
1353 | 1366 | const auto bufsiz = 16384;
|
1354 | 1367 | char buff[bufsiz];
|
1355 | 1368 | do {
|
1356 | 1369 | strm.avail_out = bufsiz;
|
1357 |
| - strm.next_out = reinterpret_cast<Bytef*>(buff); |
| 1370 | + strm.next_out = reinterpret_cast<Bytef *>(buff); |
1358 | 1371 |
|
1359 | 1372 | ret = inflate(&strm, Z_NO_FLUSH);
|
1360 | 1373 | assert(ret != Z_STREAM_ERROR);
|
@@ -2326,8 +2339,9 @@ inline void Server::stop() {
|
2326 | 2339 | }
|
2327 | 2340 |
|
2328 | 2341 | inline bool Server::parse_request_line(const char *s, Request &req) {
|
2329 |
| - static std::regex re("(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI) " |
2330 |
| - "(([^?]+)(?:\\?(.+?))?) (HTTP/1\\.[01])\r\n"); |
| 2342 | + static std::regex re( |
| 2343 | + "(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI) " |
| 2344 | + "(([^?]+)(?:\\?(.+?))?) (HTTP/1\\.[01])\r\n"); |
2331 | 2345 |
|
2332 | 2346 | std::cmatch m;
|
2333 | 2347 | if (std::regex_match(s, m, re)) {
|
@@ -2688,7 +2702,8 @@ Server::process_request(Stream &strm, bool last_connection,
|
2688 | 2702 | req.set_header("REMOTE_ADDR", strm.get_remote_addr());
|
2689 | 2703 |
|
2690 | 2704 | // Body
|
2691 |
| - if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" || req.method == "PRI") { |
| 2705 | + if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" || |
| 2706 | + req.method == "PRI") { |
2692 | 2707 | if (!detail::read_content(strm, req, payload_max_length_, res.status,
|
2693 | 2708 | Progress(), [&](const char *buf, size_t n) {
|
2694 | 2709 | if (req.body.size() + n > req.body.max_size()) {
|
@@ -2820,7 +2835,8 @@ inline bool Client::send(const std::vector<Request> &requests,
|
2820 | 2835 |
|
2821 | 2836 | if (!process_and_close_socket(
|
2822 | 2837 | sock, requests.size() - i,
|
2823 |
| - [&](Stream &strm, bool last_connection, bool &connection_close) -> bool { |
| 2838 | + [&](Stream &strm, bool last_connection, |
| 2839 | + bool &connection_close) -> bool { |
2824 | 2840 | auto &req = requests[i];
|
2825 | 2841 | auto res = Response();
|
2826 | 2842 | i++;
|
@@ -3386,17 +3402,18 @@ class SSLThreadLocks {
|
3386 | 3402 | class SSLInit {
|
3387 | 3403 | public:
|
3388 | 3404 | SSLInit() {
|
3389 |
| -#if OPENSSL_VERSION_NUMBER >= 0x1010001fL |
3390 |
| - OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); |
3391 |
| -#else |
| 3405 | +#if OPENSSL_VERSION_NUMBER < 0x1010001fL |
3392 | 3406 | SSL_load_error_strings();
|
3393 | 3407 | SSL_library_init();
|
| 3408 | +#else |
| 3409 | + OPENSSL_init_ssl( |
| 3410 | + OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); |
3394 | 3411 | #endif
|
3395 | 3412 | }
|
3396 | 3413 |
|
3397 | 3414 | ~SSLInit() {
|
3398 | 3415 | #if OPENSSL_VERSION_NUMBER < 0x1010001fL
|
3399 |
| - ERR_free_strings(); |
| 3416 | + ERR_free_strings(); |
3400 | 3417 | #endif
|
3401 | 3418 | }
|
3402 | 3419 |
|
@@ -3539,9 +3556,7 @@ inline long SSLClient::get_openssl_verify_result() const {
|
3539 | 3556 | return verify_result_;
|
3540 | 3557 | }
|
3541 | 3558 |
|
3542 |
| -inline SSL_CTX* SSLClient::ssl_context() const noexcept { |
3543 |
| - return ctx_; |
3544 |
| -} |
| 3559 | +inline SSL_CTX *SSLClient::ssl_context() const noexcept { return ctx_; } |
3545 | 3560 |
|
3546 | 3561 | inline bool SSLClient::process_and_close_socket(
|
3547 | 3562 | socket_t sock, size_t request_count,
|
|
0 commit comments