Skip to content

Commit ed0719f

Browse files
committed
Code format
1 parent 6a848b1 commit ed0719f

File tree

2 files changed

+90
-70
lines changed

2 files changed

+90
-70
lines changed

httplib.h

+45-30
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ class ThreadPool final : public TaskQueue {
728728
}
729729

730730
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
731-
OPENSSL_thread_stop ();
731+
OPENSSL_thread_stop();
732732
#endif
733733
}
734734

@@ -1824,9 +1824,9 @@ class SSLServer : public Server {
18241824
bool is_valid() const override;
18251825

18261826
SSL_CTX *ssl_context() const;
1827-
1828-
void update_certs (X509 *cert, EVP_PKEY *private_key,
1829-
X509_STORE *client_ca_cert_store = nullptr);
1827+
1828+
void update_certs(X509 *cert, EVP_PKEY *private_key,
1829+
X509_STORE *client_ca_cert_store = nullptr);
18301830

18311831
private:
18321832
bool process_and_close_socket(socket_t sock) override;
@@ -2824,7 +2824,9 @@ inline bool mmap::open(const char *path) {
28242824
wpath += path[i];
28252825
}
28262826

2827-
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
2827+
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | \
2828+
WINAPI_PARTITION_GAMES) && \
2829+
(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
28282830
hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ,
28292831
OPEN_EXISTING, NULL);
28302832
#else
@@ -2834,7 +2836,8 @@ inline bool mmap::open(const char *path) {
28342836

28352837
if (hFile_ == INVALID_HANDLE_VALUE) { return false; }
28362838

2837-
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES)
2839+
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | \
2840+
WINAPI_PARTITION_GAMES)
28382841
LARGE_INTEGER size{};
28392842
if (!::GetFileSizeEx(hFile_, &size)) { return false; }
28402843
size_ = static_cast<size_t>(size.QuadPart);
@@ -2846,21 +2849,22 @@ inline bool mmap::open(const char *path) {
28462849
size_ = (static_cast<size_t>(sizeHigh) << (sizeof(DWORD) * 8)) | sizeLow;
28472850
#endif
28482851

2849-
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
2852+
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && \
2853+
(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
28502854
hMapping_ =
28512855
::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL);
28522856
#else
2853-
hMapping_ =
2854-
::CreateFileMappingW(hFile_, NULL, PAGE_READONLY, size.HighPart,
2855-
size.LowPart, NULL);
2857+
hMapping_ = ::CreateFileMappingW(hFile_, NULL, PAGE_READONLY, size.HighPart,
2858+
size.LowPart, NULL);
28562859
#endif
28572860

28582861
if (hMapping_ == NULL) {
28592862
close();
28602863
return false;
28612864
}
28622865

2863-
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
2866+
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && \
2867+
(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
28642868
addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0);
28652869
#else
28662870
addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0);
@@ -8185,7 +8189,8 @@ inline Result ClientImpl::Patch(const std::string &path,
81858189

81868190
inline Result ClientImpl::Patch(const std::string &path,
81878191
const std::string &body,
8188-
const std::string &content_type, Progress progress) {
8192+
const std::string &content_type,
8193+
Progress progress) {
81898194
return Patch(path, Headers(), body, content_type, progress);
81908195
}
81918196

@@ -8784,17 +8789,17 @@ inline bool SSLServer::is_valid() const { return ctx_; }
87848789

87858790
inline SSL_CTX *SSLServer::ssl_context() const { return ctx_; }
87868791

8787-
inline void SSLServer::update_certs (X509 *cert, EVP_PKEY *private_key,
8788-
X509_STORE *client_ca_cert_store) {
8792+
inline void SSLServer::update_certs(X509 *cert, EVP_PKEY *private_key,
8793+
X509_STORE *client_ca_cert_store) {
87898794

8790-
std::lock_guard<std::mutex> guard(ctx_mutex_);
8795+
std::lock_guard<std::mutex> guard(ctx_mutex_);
87918796

8792-
SSL_CTX_use_certificate (ctx_, cert);
8793-
SSL_CTX_use_PrivateKey (ctx_, private_key);
8797+
SSL_CTX_use_certificate(ctx_, cert);
8798+
SSL_CTX_use_PrivateKey(ctx_, private_key);
87948799

8795-
if (client_ca_cert_store != nullptr) {
8796-
SSL_CTX_set_cert_store (ctx_, client_ca_cert_store);
8797-
}
8800+
if (client_ca_cert_store != nullptr) {
8801+
SSL_CTX_set_cert_store(ctx_, client_ca_cert_store);
8802+
}
87988803
}
87998804

88008805
inline bool SSLServer::process_and_close_socket(socket_t sock) {
@@ -9579,7 +9584,8 @@ inline Result Client::Patch(const std::string &path, const char *body,
95799584
}
95809585
inline Result Client::Patch(const std::string &path, const char *body,
95819586
size_t content_length,
9582-
const std::string &content_type, Progress progress) {
9587+
const std::string &content_type,
9588+
Progress progress) {
95839589
return cli_->Patch(path, body, content_length, content_type, progress);
95849590
}
95859591
inline Result Client::Patch(const std::string &path, const Headers &headers,
@@ -9589,15 +9595,18 @@ inline Result Client::Patch(const std::string &path, const Headers &headers,
95899595
}
95909596
inline Result Client::Patch(const std::string &path, const Headers &headers,
95919597
const char *body, size_t content_length,
9592-
const std::string &content_type, Progress progress) {
9593-
return cli_->Patch(path, headers, body, content_length, content_type, progress);
9598+
const std::string &content_type,
9599+
Progress progress) {
9600+
return cli_->Patch(path, headers, body, content_length, content_type,
9601+
progress);
95949602
}
95959603
inline Result Client::Patch(const std::string &path, const std::string &body,
95969604
const std::string &content_type) {
95979605
return cli_->Patch(path, body, content_type);
95989606
}
95999607
inline Result Client::Patch(const std::string &path, const std::string &body,
9600-
const std::string &content_type, Progress progress) {
9608+
const std::string &content_type,
9609+
Progress progress) {
96019610
return cli_->Patch(path, body, content_type, progress);
96029611
}
96039612
inline Result Client::Patch(const std::string &path, const Headers &headers,
@@ -9607,7 +9616,8 @@ inline Result Client::Patch(const std::string &path, const Headers &headers,
96079616
}
96089617
inline Result Client::Patch(const std::string &path, const Headers &headers,
96099618
const std::string &body,
9610-
const std::string &content_type, Progress progress) {
9619+
const std::string &content_type,
9620+
Progress progress) {
96119621
return cli_->Patch(path, headers, body, content_type, progress);
96129622
}
96139623
inline Result Client::Patch(const std::string &path, size_t content_length,
@@ -9646,7 +9656,8 @@ inline Result Client::Delete(const std::string &path, const char *body,
96469656
}
96479657
inline Result Client::Delete(const std::string &path, const char *body,
96489658
size_t content_length,
9649-
const std::string &content_type, Progress progress) {
9659+
const std::string &content_type,
9660+
Progress progress) {
96509661
return cli_->Delete(path, body, content_length, content_type, progress);
96519662
}
96529663
inline Result Client::Delete(const std::string &path, const Headers &headers,
@@ -9656,15 +9667,18 @@ inline Result Client::Delete(const std::string &path, const Headers &headers,
96569667
}
96579668
inline Result Client::Delete(const std::string &path, const Headers &headers,
96589669
const char *body, size_t content_length,
9659-
const std::string &content_type, Progress progress) {
9660-
return cli_->Delete(path, headers, body, content_length, content_type, progress);
9670+
const std::string &content_type,
9671+
Progress progress) {
9672+
return cli_->Delete(path, headers, body, content_length, content_type,
9673+
progress);
96619674
}
96629675
inline Result Client::Delete(const std::string &path, const std::string &body,
96639676
const std::string &content_type) {
96649677
return cli_->Delete(path, body, content_type);
96659678
}
96669679
inline Result Client::Delete(const std::string &path, const std::string &body,
9667-
const std::string &content_type, Progress progress) {
9680+
const std::string &content_type,
9681+
Progress progress) {
96689682
return cli_->Delete(path, body, content_type, progress);
96699683
}
96709684
inline Result Client::Delete(const std::string &path, const Headers &headers,
@@ -9674,7 +9688,8 @@ inline Result Client::Delete(const std::string &path, const Headers &headers,
96749688
}
96759689
inline Result Client::Delete(const std::string &path, const Headers &headers,
96769690
const std::string &body,
9677-
const std::string &content_type, Progress progress) {
9691+
const std::string &content_type,
9692+
Progress progress) {
96789693
return cli_->Delete(path, headers, body, content_type, progress);
96799694
}
96809695
inline Result Client::Options(const std::string &path) {

test/test.cc

+45-40
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ TEST(ClientTest, MoveConstructible) {
5959
EXPECT_TRUE(std::is_nothrow_move_constructible<Client>::value);
6060
}
6161

62-
TEST(ClientTest, MoveAssignable)
63-
{
64-
EXPECT_FALSE(std::is_copy_assignable<Client>::value);
65-
EXPECT_TRUE(std::is_nothrow_move_assignable<Client>::value);
62+
TEST(ClientTest, MoveAssignable) {
63+
EXPECT_FALSE(std::is_copy_assignable<Client>::value);
64+
EXPECT_TRUE(std::is_nothrow_move_assignable<Client>::value);
6665
}
6766

6867
#ifdef _WIN32
@@ -1755,32 +1754,34 @@ TEST(BindServerTest, BindAndListenSeparatelySSLEncryptedKey) {
17551754
#endif
17561755

17571756
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1758-
X509* readCertificate (const std::string& strFileName) {
1759-
std::ifstream inStream (strFileName);
1760-
std::string strCertPEM ((std::istreambuf_iterator<char>(inStream)), std::istreambuf_iterator<char>());
1757+
X509 *readCertificate(const std::string &strFileName) {
1758+
std::ifstream inStream(strFileName);
1759+
std::string strCertPEM((std::istreambuf_iterator<char>(inStream)),
1760+
std::istreambuf_iterator<char>());
17611761

1762-
if (strCertPEM.empty ()) return (nullptr);
1762+
if (strCertPEM.empty()) return (nullptr);
17631763

1764-
BIO* pbCert = BIO_new (BIO_s_mem ());
1765-
BIO_write (pbCert, strCertPEM.c_str (), (int)strCertPEM.size ());
1766-
X509* pCert = PEM_read_bio_X509 (pbCert, NULL, 0, NULL);
1767-
BIO_free (pbCert);
1764+
BIO *pbCert = BIO_new(BIO_s_mem());
1765+
BIO_write(pbCert, strCertPEM.c_str(), (int)strCertPEM.size());
1766+
X509 *pCert = PEM_read_bio_X509(pbCert, NULL, 0, NULL);
1767+
BIO_free(pbCert);
17681768

1769-
return (pCert);
1769+
return (pCert);
17701770
}
17711771

1772-
EVP_PKEY* readPrivateKey (const std::string& strFileName) {
1773-
std::ifstream inStream (strFileName);
1774-
std::string strPrivateKeyPEM ((std::istreambuf_iterator<char>(inStream)), std::istreambuf_iterator<char>());
1772+
EVP_PKEY *readPrivateKey(const std::string &strFileName) {
1773+
std::ifstream inStream(strFileName);
1774+
std::string strPrivateKeyPEM((std::istreambuf_iterator<char>(inStream)),
1775+
std::istreambuf_iterator<char>());
17751776

1776-
if (strPrivateKeyPEM.empty ()) return (nullptr);
1777+
if (strPrivateKeyPEM.empty()) return (nullptr);
17771778

1778-
BIO* pbPrivKey = BIO_new (BIO_s_mem ());
1779-
BIO_write (pbPrivKey, strPrivateKeyPEM.c_str (), (int) strPrivateKeyPEM.size ());
1780-
EVP_PKEY* pPrivateKey = PEM_read_bio_PrivateKey (pbPrivKey, NULL, NULL, NULL);
1781-
BIO_free (pbPrivKey);
1779+
BIO *pbPrivKey = BIO_new(BIO_s_mem());
1780+
BIO_write(pbPrivKey, strPrivateKeyPEM.c_str(), (int)strPrivateKeyPEM.size());
1781+
EVP_PKEY *pPrivateKey = PEM_read_bio_PrivateKey(pbPrivKey, NULL, NULL, NULL);
1782+
BIO_free(pbPrivKey);
17821783

1783-
return (pPrivateKey);
1784+
return (pPrivateKey);
17841785
}
17851786

17861787
TEST(BindServerTest, UpdateCerts) {
@@ -1789,26 +1790,26 @@ TEST(BindServerTest, UpdateCerts) {
17891790
ASSERT_TRUE(svr.is_valid());
17901791
ASSERT_TRUE(port > 0);
17911792

1792-
X509* cert = readCertificate (SERVER_CERT_FILE);
1793-
X509* ca_cert = readCertificate (CLIENT_CA_CERT_FILE);
1794-
EVP_PKEY* key = readPrivateKey (SERVER_PRIVATE_KEY_FILE);
1793+
X509 *cert = readCertificate(SERVER_CERT_FILE);
1794+
X509 *ca_cert = readCertificate(CLIENT_CA_CERT_FILE);
1795+
EVP_PKEY *key = readPrivateKey(SERVER_PRIVATE_KEY_FILE);
17951796

1796-
ASSERT_TRUE(cert != nullptr);
1797+
ASSERT_TRUE(cert != nullptr);
17971798
ASSERT_TRUE(ca_cert != nullptr);
1798-
ASSERT_TRUE(key != nullptr);
1799+
ASSERT_TRUE(key != nullptr);
17991800

1800-
X509_STORE* cert_store = X509_STORE_new ();
1801+
X509_STORE *cert_store = X509_STORE_new();
18011802

1802-
X509_STORE_add_cert (cert_store, ca_cert);
1803+
X509_STORE_add_cert(cert_store, ca_cert);
18031804

1804-
svr.update_certs (cert, key, cert_store);
1805+
svr.update_certs(cert, key, cert_store);
18051806

18061807
ASSERT_TRUE(svr.is_valid());
18071808
svr.stop();
18081809

1809-
X509_free (cert);
1810-
X509_free (ca_cert);
1811-
EVP_PKEY_free (key);
1810+
X509_free(cert);
1811+
X509_free(ca_cert);
1812+
EVP_PKEY_free(key);
18121813
}
18131814
#endif
18141815

@@ -2357,8 +2358,8 @@ class ServerTest : public ::testing::Test {
23572358
})
23582359
.Get("/with-range-customized-response",
23592360
[&](const Request & /*req*/, Response &res) {
2360-
res.status = StatusCode::BadRequest_400;
2361-
res.set_content(JSON_DATA, "application/json");
2361+
res.status = StatusCode::BadRequest_400;
2362+
res.set_content(JSON_DATA, "application/json");
23622363
})
23632364
.Post("/chunked",
23642365
[&](const Request &req, Response & /*res*/) {
@@ -3480,8 +3481,10 @@ TEST_F(ServerTest, GetStreamedWithRangeError) {
34803481
}
34813482

34823483
TEST_F(ServerTest, GetRangeWithMaxLongLength) {
3483-
auto res =
3484-
cli_.Get("/with-range", {{"Range", "bytes=0-" + std::to_string(std::numeric_limits<long>::max())}});
3484+
auto res = cli_.Get(
3485+
"/with-range",
3486+
{{"Range",
3487+
"bytes=0-" + std::to_string(std::numeric_limits<long>::max())}});
34853488
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
34863489
EXPECT_EQ("0", res->get_header_value("Content-Length"));
34873490
EXPECT_EQ(false, res->has_header("Content-Range"));
@@ -3637,7 +3640,8 @@ TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
36373640
}
36383641

36393642
TEST_F(ServerTest, GetWithRangeCustomizedResponse) {
3640-
auto res = cli_.Get("/with-range-customized-response", {{make_range_header({{1, 2}})}});
3643+
auto res = cli_.Get("/with-range-customized-response",
3644+
{{make_range_header({{1, 2}})}});
36413645
ASSERT_TRUE(res);
36423646
EXPECT_EQ(StatusCode::BadRequest_400, res->status);
36433647
EXPECT_EQ(true, res->has_header("Content-Length"));
@@ -3646,7 +3650,8 @@ TEST_F(ServerTest, GetWithRangeCustomizedResponse) {
36463650
}
36473651

36483652
TEST_F(ServerTest, GetWithRangeMultipartCustomizedResponseMultipleRange) {
3649-
auto res = cli_.Get("/with-range-customized-response", {{make_range_header({{1, 2}, {4, 5}})}});
3653+
auto res = cli_.Get("/with-range-customized-response",
3654+
{{make_range_header({{1, 2}, {4, 5}})}});
36503655
ASSERT_TRUE(res);
36513656
EXPECT_EQ(StatusCode::BadRequest_400, res->status);
36523657
EXPECT_EQ(true, res->has_header("Content-Length"));
@@ -7450,6 +7455,6 @@ TEST(UniversalClientImplTest, Ipv6LiteralAddress) {
74507455
std::string ipV6TestURL = "http://[ff06::c3]";
74517456

74527457
Client cli(ipV6TestURL + ":" + std::to_string(port), CLIENT_CERT_FILE,
7453-
CLIENT_PRIVATE_KEY_FILE);
7458+
CLIENT_PRIVATE_KEY_FILE);
74547459
EXPECT_EQ(cli.port(), port);
74557460
}

0 commit comments

Comments
 (0)