Skip to content

Commit

Permalink
Code format
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Dec 31, 2020
1 parent 242706e commit 3f88a46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
3 changes: 2 additions & 1 deletion httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,8 @@ inline bool load_system_certs_on_windows(X509_STORE *store) {
if (!hStore) { return false; }

PCCERT_CONTEXT pContext = NULL;
while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != nullptr) {
while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) !=
nullptr) {
auto encoded_cert =
static_cast<const unsigned char *>(pContext->pbCertEncoded);

Expand Down
50 changes: 41 additions & 9 deletions test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ TEST(EncodeQueryParamTest, ParseReservedCharactersTest) {
"%3B%2C%2F%3F%3A%40%26%3D%2B%24");
}

TEST(EncodeQueryParamTest, TestUTF8Characters){
TEST(EncodeQueryParamTest, TestUTF8Characters) {
string chineseCharacters = "中国語";
string russianCharacters = "дом";
string brazilianCharacters = "óculos";

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

EXPECT_EQ(detail::encode_query_param(russianCharacters),
"%D0%B4%D0%BE%D0%BC");
"%D0%B4%D0%BE%D0%BC");

EXPECT_EQ(detail::encode_query_param(brazilianCharacters),
"%C3%B3culos");
EXPECT_EQ(detail::encode_query_param(brazilianCharacters), "%C3%B3culos");
}

TEST(TrimTests, TrimStringTests) {
Expand Down Expand Up @@ -3150,7 +3149,7 @@ TEST(ExceptionTest, ThrowExceptionInHandler) {

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

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

TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
Server svr;

svr.set_error_handler([](Request const &, Response &res) -> void {
res.set_chunked_content_provider(
"text/plain", [](std::size_t const, DataSink &sink) -> bool {
sink.os << "hello";
sink.os << "world";
sink.done();
return true;
});
});

auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
while (!svr.is_running()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

// Give GET time to get a few messages.
std::this_thread::sleep_for(std::chrono::seconds(1));

Client cli("localhost", PORT);

auto res = cli.Get("/");
ASSERT_TRUE(res);
EXPECT_EQ(404, res->status);
EXPECT_EQ("helloworld", res->body);

svr.stop();
listen_thread.join();
ASSERT_FALSE(svr.is_running());
}

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
TEST(KeepAliveTest, ReadTimeoutSSL) {
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
Expand Down Expand Up @@ -3770,9 +3802,9 @@ TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
Client cli("https://nghttp2.org");
cli.set_follow_location(true);
auto res = cli.Get(
"/httpbin/"
"redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
auto res =
cli.Get("/httpbin/"
"redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");

ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
Expand Down

0 comments on commit 3f88a46

Please sign in to comment.