Skip to content

Commit 3f88a46

Browse files
committed
Code format
1 parent 242706e commit 3f88a46

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

httplib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,8 @@ inline bool load_system_certs_on_windows(X509_STORE *store) {
35553555
if (!hStore) { return false; }
35563556

35573557
PCCERT_CONTEXT pContext = NULL;
3558-
while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != nullptr) {
3558+
while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) !=
3559+
nullptr) {
35593560
auto encoded_cert =
35603561
static_cast<const unsigned char *>(pContext->pbCertEncoded);
35613562

test/test.cc

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,18 @@ TEST(EncodeQueryParamTest, ParseReservedCharactersTest) {
5959
"%3B%2C%2F%3F%3A%40%26%3D%2B%24");
6060
}
6161

62-
TEST(EncodeQueryParamTest, TestUTF8Characters){
62+
TEST(EncodeQueryParamTest, TestUTF8Characters) {
6363
string chineseCharacters = "中国語";
6464
string russianCharacters = "дом";
6565
string brazilianCharacters = "óculos";
6666

6767
EXPECT_EQ(detail::encode_query_param(chineseCharacters),
68-
"%E4%B8%AD%E5%9B%BD%E8%AA%9E");
68+
"%E4%B8%AD%E5%9B%BD%E8%AA%9E");
6969

7070
EXPECT_EQ(detail::encode_query_param(russianCharacters),
71-
"%D0%B4%D0%BE%D0%BC");
71+
"%D0%B4%D0%BE%D0%BC");
7272

73-
EXPECT_EQ(detail::encode_query_param(brazilianCharacters),
74-
"%C3%B3culos");
73+
EXPECT_EQ(detail::encode_query_param(brazilianCharacters), "%C3%B3culos");
7574
}
7675

7776
TEST(TrimTests, TrimStringTests) {
@@ -3150,7 +3149,7 @@ TEST(ExceptionTest, ThrowExceptionInHandler) {
31503149

31513150
svr.Get("/hi", [&](const Request & /*req*/, Response & /*res*/) {
31523151
throw std::runtime_error("exception...");
3153-
//res.set_content("Hello World!", "text/plain");
3152+
// res.set_content("Hello World!", "text/plain");
31543153
});
31553154

31563155
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
@@ -3211,6 +3210,39 @@ TEST(KeepAliveTest, ReadTimeout) {
32113210
ASSERT_FALSE(svr.is_running());
32123211
}
32133212

3213+
TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
3214+
Server svr;
3215+
3216+
svr.set_error_handler([](Request const &, Response &res) -> void {
3217+
res.set_chunked_content_provider(
3218+
"text/plain", [](std::size_t const, DataSink &sink) -> bool {
3219+
sink.os << "hello";
3220+
sink.os << "world";
3221+
sink.done();
3222+
return true;
3223+
});
3224+
});
3225+
3226+
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
3227+
while (!svr.is_running()) {
3228+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
3229+
}
3230+
3231+
// Give GET time to get a few messages.
3232+
std::this_thread::sleep_for(std::chrono::seconds(1));
3233+
3234+
Client cli("localhost", PORT);
3235+
3236+
auto res = cli.Get("/");
3237+
ASSERT_TRUE(res);
3238+
EXPECT_EQ(404, res->status);
3239+
EXPECT_EQ("helloworld", res->body);
3240+
3241+
svr.stop();
3242+
listen_thread.join();
3243+
ASSERT_FALSE(svr.is_running());
3244+
}
3245+
32143246
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
32153247
TEST(KeepAliveTest, ReadTimeoutSSL) {
32163248
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
@@ -3770,9 +3802,9 @@ TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
37703802
TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
37713803
Client cli("https://nghttp2.org");
37723804
cli.set_follow_location(true);
3773-
auto res = cli.Get(
3774-
"/httpbin/"
3775-
"redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
3805+
auto res =
3806+
cli.Get("/httpbin/"
3807+
"redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
37763808

37773809
ASSERT_TRUE(res);
37783810
EXPECT_EQ(200, res->status);

0 commit comments

Comments
 (0)