From 2996cecee0a947f681571cf0bd205a674d07b220 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 17 Feb 2025 18:14:02 +0100 Subject: [PATCH] Fix code inconsistently formatted and re-format (#2063) * Fix code inconsistently formatted by clang-format * Run clang-format --- example/ssesvr.cc | 3 +-- httplib.h | 17 ++++++++--------- test/test.cc | 11 ++++++----- test/test_proxy.cc | 33 ++++++++++++++++----------------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/example/ssesvr.cc b/example/ssesvr.cc index 5b0e0b93bf..547b864f3d 100644 --- a/example/ssesvr.cc +++ b/example/ssesvr.cc @@ -12,8 +12,7 @@ using namespace std; class EventDispatcher { public: - EventDispatcher() { - } + EventDispatcher() {} void wait_event(DataSink *sink) { unique_lock lk(m_); diff --git a/httplib.h b/httplib.h index edea018af9..66a2c6f9d2 100644 --- a/httplib.h +++ b/httplib.h @@ -5987,9 +5987,9 @@ inline ssize_t Stream::write(const std::string &s) { namespace detail { -inline void calc_actual_timeout(time_t max_timeout_msec, - time_t duration_msec, time_t timeout_sec, - time_t timeout_usec, time_t &actual_timeout_sec, +inline void calc_actual_timeout(time_t max_timeout_msec, time_t duration_msec, + time_t timeout_sec, time_t timeout_usec, + time_t &actual_timeout_sec, time_t &actual_timeout_usec) { auto timeout_msec = (timeout_sec * 1000) + (timeout_usec / 1000); @@ -8213,8 +8213,7 @@ inline bool ClientImpl::process_socket( std::function callback) { return detail::process_client_socket( socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, - write_timeout_usec_, max_timeout_msec_, start_time, - std::move(callback)); + write_timeout_usec_, max_timeout_msec_, start_time, std::move(callback)); } inline bool ClientImpl::is_ssl() const { return false; } @@ -9119,8 +9118,8 @@ inline bool process_client_socket_ssl( time_t max_timeout_msec, std::chrono::time_point start_time, T callback) { SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec, - write_timeout_sec, write_timeout_usec, - max_timeout_msec, start_time); + write_timeout_sec, write_timeout_usec, max_timeout_msec, + start_time); return callback(strm); } @@ -9735,8 +9734,8 @@ SSLClient::verify_host_with_subject_alt_name(X509 *server_cert) const { auto type = GEN_DNS; - struct in6_addr addr6{}; - struct in_addr addr{}; + struct in6_addr addr6 = {}; + struct in_addr addr = {}; size_t addr_len = 0; #ifndef __MINGW32__ diff --git a/test/test.cc b/test/test.cc index 87f991749e..423762b7a6 100644 --- a/test/test.cc +++ b/test/test.cc @@ -3553,9 +3553,11 @@ TEST_F(ServerTest, TooLongRequest) { } TEST_F(ServerTest, AlmostTooLongRequest) { - // test for #2046 - URI length check shouldn't include other content on req line - // URI is max URI length, minus 14 other chars in req line (GET, space, leading /, space, HTTP/1.1) - std::string request = "/" + string(CPPHTTPLIB_REQUEST_URI_MAX_LENGTH - 14, 'A'); + // test for #2046 - URI length check shouldn't include other content on req + // line URI is max URI length, minus 14 other chars in req line (GET, space, + // leading /, space, HTTP/1.1) + std::string request = + "/" + string(CPPHTTPLIB_REQUEST_URI_MAX_LENGTH - 14, 'A'); auto res = cli_.Get(request.c_str()); @@ -8283,7 +8285,6 @@ TEST(MaxTimeoutTest, ContentStream) { Client cli("localhost", PORT); cli.set_max_timeout(std::chrono::milliseconds(timeout)); - { auto start = std::chrono::steady_clock::now(); @@ -8345,7 +8346,7 @@ TEST(MaxTimeoutTest, ContentStreamSSL) { [&, data](size_t offset, size_t length, DataSink &sink) { const size_t DATA_CHUNK_SIZE = 4; const auto &d = *data; - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::this_thread::sleep_for(std::chrono::seconds(1)); sink.write(&d[offset], std::min(length, DATA_CHUNK_SIZE)); return true; }, diff --git a/test/test_proxy.cc b/test/test_proxy.cc index 88a8ba963d..672bcce247 100644 --- a/test/test_proxy.cc +++ b/test/test_proxy.cc @@ -5,8 +5,7 @@ using namespace std; using namespace httplib; -template -void ProxyTest(T& cli, bool basic) { +template void ProxyTest(T &cli, bool basic) { cli.set_proxy("localhost", basic ? 3128 : 3129); auto res = cli.Get("/httpbin/get"); ASSERT_TRUE(res != nullptr); @@ -38,7 +37,7 @@ TEST(ProxyTest, SSLDigest) { // ---------------------------------------------------------------------------- template -void RedirectProxyText(T& cli, const char *path, bool basic) { +void RedirectProxyText(T &cli, const char *path, bool basic) { cli.set_proxy("localhost", basic ? 3128 : 3129); if (basic) { cli.set_proxy_basic_auth("hello", "world"); @@ -100,8 +99,7 @@ TEST(RedirectTest, YouTubeSSLDigest) { // ---------------------------------------------------------------------------- -template -void BaseAuthTestFromHTTPWatch(T& cli) { +template void BaseAuthTestFromHTTPWatch(T &cli) { cli.set_proxy("localhost", 3128); cli.set_proxy_basic_auth("hello", "world"); @@ -112,11 +110,11 @@ void BaseAuthTestFromHTTPWatch(T& cli) { } { - auto res = - cli.Get("/basic-auth/hello/world", - {make_basic_authentication_header("hello", "world")}); + auto res = cli.Get("/basic-auth/hello/world", + {make_basic_authentication_header("hello", "world")}); ASSERT_TRUE(res != nullptr); - EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body); + EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", + res->body); EXPECT_EQ(StatusCode::OK_200, res->status); } @@ -124,7 +122,8 @@ void BaseAuthTestFromHTTPWatch(T& cli) { cli.set_basic_auth("hello", "world"); auto res = cli.Get("/basic-auth/hello/world"); ASSERT_TRUE(res != nullptr); - EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body); + EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", + res->body); EXPECT_EQ(StatusCode::OK_200, res->status); } @@ -158,8 +157,7 @@ TEST(BaseAuthTest, SSL) { // ---------------------------------------------------------------------------- #ifdef CPPHTTPLIB_OPENSSL_SUPPORT -template -void DigestAuthTestFromHTTPWatch(T& cli) { +template void DigestAuthTestFromHTTPWatch(T &cli) { cli.set_proxy("localhost", 3129); cli.set_proxy_digest_auth("hello", "world"); @@ -181,7 +179,8 @@ void DigestAuthTestFromHTTPWatch(T& cli) { for (auto path : paths) { auto res = cli.Get(path.c_str()); ASSERT_TRUE(res != nullptr); - EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body); + EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", + res->body); EXPECT_EQ(StatusCode::OK_200, res->status); } @@ -216,8 +215,7 @@ TEST(DigestAuthTest, NoSSL) { // ---------------------------------------------------------------------------- -template -void KeepAliveTest(T& cli, bool basic) { +template void KeepAliveTest(T &cli, bool basic) { cli.set_proxy("localhost", basic ? 3128 : 3129); if (basic) { cli.set_proxy_basic_auth("hello", "world"); @@ -249,9 +247,10 @@ void KeepAliveTest(T& cli, bool basic) { "/httpbin/digest-auth/auth-int/hello/world/MD5", }; - for (auto path: paths) { + for (auto path : paths) { auto res = cli.Get(path.c_str()); - EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body); + EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", + res->body); EXPECT_EQ(StatusCode::OK_200, res->status); } }