Skip to content

Commit 380f725

Browse files
committed
Code format
1 parent a106bd3 commit 380f725

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

httplib.h

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/*
1212
* Configuration
1313
*/
14+
1415
#ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
1516
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
1617
#endif
@@ -60,6 +61,10 @@
6061
#define _CRT_NONSTDC_NO_DEPRECATE
6162
#endif //_CRT_NONSTDC_NO_DEPRECATE
6263

64+
/*
65+
* Headers
66+
*/
67+
6368
#if defined(_MSC_VER)
6469
#ifdef _WIN64
6570
typedef __int64 ssize_t;
@@ -162,6 +167,9 @@ inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1) {
162167
#include <zlib.h>
163168
#endif
164169

170+
/*
171+
* Declaration
172+
*/
165173
namespace httplib {
166174

167175
namespace detail {
@@ -742,7 +750,7 @@ class SSLClient : public Client {
742750

743751
long get_openssl_verify_result() const;
744752

745-
SSL_CTX* ssl_context() const noexcept;
753+
SSL_CTX *ssl_context() const noexcept;
746754

747755
private:
748756
virtual bool process_and_close_socket(
@@ -770,6 +778,7 @@ class SSLClient : public Client {
770778
/*
771779
* Implementation
772780
*/
781+
773782
namespace detail {
774783

775784
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) {
10661075
pfd_read.revents & (POLLIN | POLLOUT)) {
10671076
int error = 0;
10681077
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 &&
10701080
!error;
10711081
}
10721082
return false;
@@ -1177,9 +1187,11 @@ socket_t create_socket(const char *host, int port, Fn fn,
11771187

11781188
// Make 'reuse address' option available
11791189
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));
11811192
#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));
11831195
#endif
11841196

11851197
// bind or connect
@@ -1221,8 +1233,8 @@ inline std::string get_remote_addr(socket_t sock) {
12211233
if (!getpeername(sock, reinterpret_cast<struct sockaddr *>(&addr), &len)) {
12221234
char ipstr[NI_MAXHOST];
12231235

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)) {
12261238
return ipstr;
12271239
}
12281240
}
@@ -1303,15 +1315,16 @@ inline bool compress(std::string &content) {
13031315
if (ret != Z_OK) { return false; }
13041316

13051317
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()));
13071320

13081321
std::string compressed;
13091322

13101323
const auto bufsiz = 16384;
13111324
char buff[bufsiz];
13121325
do {
13131326
strm.avail_out = bufsiz;
1314-
strm.next_out = reinterpret_cast<Bytef*>(buff);
1327+
strm.next_out = reinterpret_cast<Bytef *>(buff);
13151328
ret = deflate(&strm, Z_FINISH);
13161329
assert(ret != Z_STREAM_ERROR);
13171330
compressed.append(buff, bufsiz - strm.avail_out);
@@ -1348,13 +1361,13 @@ class decompressor {
13481361
int ret = Z_OK;
13491362

13501363
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));
13521365

13531366
const auto bufsiz = 16384;
13541367
char buff[bufsiz];
13551368
do {
13561369
strm.avail_out = bufsiz;
1357-
strm.next_out = reinterpret_cast<Bytef*>(buff);
1370+
strm.next_out = reinterpret_cast<Bytef *>(buff);
13581371

13591372
ret = inflate(&strm, Z_NO_FLUSH);
13601373
assert(ret != Z_STREAM_ERROR);
@@ -2326,8 +2339,9 @@ inline void Server::stop() {
23262339
}
23272340

23282341
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");
23312345

23322346
std::cmatch m;
23332347
if (std::regex_match(s, m, re)) {
@@ -2688,7 +2702,8 @@ Server::process_request(Stream &strm, bool last_connection,
26882702
req.set_header("REMOTE_ADDR", strm.get_remote_addr());
26892703

26902704
// 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") {
26922707
if (!detail::read_content(strm, req, payload_max_length_, res.status,
26932708
Progress(), [&](const char *buf, size_t n) {
26942709
if (req.body.size() + n > req.body.max_size()) {
@@ -2820,7 +2835,8 @@ inline bool Client::send(const std::vector<Request> &requests,
28202835

28212836
if (!process_and_close_socket(
28222837
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 {
28242840
auto &req = requests[i];
28252841
auto res = Response();
28262842
i++;
@@ -3386,17 +3402,18 @@ class SSLThreadLocks {
33863402
class SSLInit {
33873403
public:
33883404
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
33923406
SSL_load_error_strings();
33933407
SSL_library_init();
3408+
#else
3409+
OPENSSL_init_ssl(
3410+
OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
33943411
#endif
33953412
}
33963413

33973414
~SSLInit() {
33983415
#if OPENSSL_VERSION_NUMBER < 0x1010001fL
3399-
ERR_free_strings();
3416+
ERR_free_strings();
34003417
#endif
34013418
}
34023419

@@ -3539,9 +3556,7 @@ inline long SSLClient::get_openssl_verify_result() const {
35393556
return verify_result_;
35403557
}
35413558

3542-
inline SSL_CTX* SSLClient::ssl_context() const noexcept {
3543-
return ctx_;
3544-
}
3559+
inline SSL_CTX *SSLClient::ssl_context() const noexcept { return ctx_; }
35453560

35463561
inline bool SSLClient::process_and_close_socket(
35473562
socket_t sock, size_t request_count,

0 commit comments

Comments
 (0)