Skip to content

Commit 63643e6

Browse files
committed
Code format
1 parent 6cc2edc commit 63643e6

File tree

2 files changed

+103
-89
lines changed

2 files changed

+103
-89
lines changed

httplib.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,9 @@ inline int shutdown_socket(socket_t sock) {
20652065
}
20662066

20672067
template <typename BindOrConnect>
2068-
socket_t create_socket(const char *host, int port, int address_family, int socket_flags,
2069-
bool tcp_nodelay, SocketOptions socket_options,
2068+
socket_t create_socket(const char *host, int port, int address_family,
2069+
int socket_flags, bool tcp_nodelay,
2070+
SocketOptions socket_options,
20702071
BindOrConnect bind_or_connect) {
20712072
// Get address info
20722073
struct addrinfo hints;
@@ -2214,8 +2215,7 @@ inline std::string if2ip(const std::string &ifn) {
22142215
#endif
22152216

22162217
inline socket_t create_client_socket(const char *host, int port,
2217-
int address_family,
2218-
bool tcp_nodelay,
2218+
int address_family, bool tcp_nodelay,
22192219
SocketOptions socket_options,
22202220
time_t timeout_sec, time_t timeout_usec,
22212221
const std::string &intf, Error &error) {
@@ -4771,7 +4771,8 @@ inline socket_t
47714771
Server::create_server_socket(const char *host, int port, int socket_flags,
47724772
SocketOptions socket_options) const {
47734773
return detail::create_socket(
4774-
host, port, address_family_, socket_flags, tcp_nodelay_, std::move(socket_options),
4774+
host, port, address_family_, socket_flags, tcp_nodelay_,
4775+
std::move(socket_options),
47754776
[](socket_t sock, struct addrinfo &ai) -> bool {
47764777
if (::bind(sock, ai.ai_addr, static_cast<socklen_t>(ai.ai_addrlen))) {
47774778
return false;
@@ -5260,8 +5261,9 @@ inline void ClientImpl::copy_settings(const ClientImpl &rhs) {
52605261
inline socket_t ClientImpl::create_client_socket(Error &error) const {
52615262
if (!proxy_host_.empty() && proxy_port_ != -1) {
52625263
return detail::create_client_socket(
5263-
proxy_host_.c_str(), proxy_port_, address_family_, tcp_nodelay_, socket_options_,
5264-
connection_timeout_sec_, connection_timeout_usec_, interface_, error);
5264+
proxy_host_.c_str(), proxy_port_, address_family_, tcp_nodelay_,
5265+
socket_options_, connection_timeout_sec_, connection_timeout_usec_,
5266+
interface_, error);
52655267
}
52665268
return detail::create_client_socket(
52675269
host_.c_str(), port_, address_family_, tcp_nodelay_, socket_options_,
@@ -6392,7 +6394,9 @@ inline void ClientImpl::set_default_headers(Headers headers) {
63926394
default_headers_ = std::move(headers);
63936395
}
63946396

6395-
inline void ClientImpl::set_address_family(int family) { address_family_ = family; }
6397+
inline void ClientImpl::set_address_family(int family) {
6398+
address_family_ = family;
6399+
}
63966400

63976401
inline void ClientImpl::set_tcp_nodelay(bool on) { tcp_nodelay_ = on; }
63986402

@@ -7456,7 +7460,9 @@ inline void Client::set_default_headers(Headers headers) {
74567460
cli_->set_default_headers(std::move(headers));
74577461
}
74587462

7459-
inline void Client::set_address_family(int family) { cli_->set_address_family(family); }
7463+
inline void Client::set_address_family(int family) {
7464+
cli_->set_address_family(family);
7465+
}
74607466

74617467
inline void Client::set_tcp_nodelay(bool on) { cli_->set_tcp_nodelay(on); }
74627468

test/test.cc

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,16 @@ TEST(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {
417417
cli.set_connection_timeout(2);
418418

419419
std::string body;
420-
auto res =
421-
cli.Get("/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137",
422-
[&](const Response &response) {
423-
EXPECT_EQ(200, response.status);
424-
return true;
425-
},
426-
[&](const char *data, size_t data_length) {
427-
body.append(data, data_length);
428-
return true;
429-
});
420+
auto res = cli.Get(
421+
"/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137",
422+
[&](const Response &response) {
423+
EXPECT_EQ(200, response.status);
424+
return true;
425+
},
426+
[&](const char *data, size_t data_length) {
427+
body.append(data, data_length);
428+
return true;
429+
});
430430
ASSERT_TRUE(res);
431431

432432
std::string out;
@@ -916,11 +916,10 @@ TEST(RedirectFromPageWithContent, Redirect) {
916916
cli.set_follow_location(true);
917917

918918
std::string body;
919-
auto res = cli.Get("/1",
920-
[&](const char *data, size_t data_length) {
921-
body.append(data, data_length);
922-
return true;
923-
});
919+
auto res = cli.Get("/1", [&](const char *data, size_t data_length) {
920+
body.append(data, data_length);
921+
return true;
922+
});
924923

925924
ASSERT_TRUE(res);
926925
EXPECT_EQ(200, res->status);
@@ -931,11 +930,10 @@ TEST(RedirectFromPageWithContent, Redirect) {
931930
Client cli("localhost", PORT);
932931

933932
std::string body;
934-
auto res = cli.Get("/1",
935-
[&](const char *data, size_t data_length) {
936-
body.append(data, data_length);
937-
return true;
938-
});
933+
auto res = cli.Get("/1", [&](const char *data, size_t data_length) {
934+
body.append(data, data_length);
935+
return true;
936+
});
939937

940938
ASSERT_TRUE(res);
941939
EXPECT_EQ(302, res->status);
@@ -2520,13 +2518,13 @@ TEST_F(ServerTest, SlowPost) {
25202518
char buffer[64 * 1024];
25212519
memset(buffer, 0x42, sizeof(buffer));
25222520

2523-
auto res =
2524-
cli_.Post("/slowpost", 64 * 1024 * 1024,
2525-
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2526-
sink.write(buffer, sizeof(buffer));
2527-
return true;
2528-
},
2529-
"text/plain");
2521+
auto res = cli_.Post(
2522+
"/slowpost", 64 * 1024 * 1024,
2523+
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2524+
sink.write(buffer, sizeof(buffer));
2525+
return true;
2526+
},
2527+
"text/plain");
25302528

25312529
ASSERT_TRUE(res);
25322530
EXPECT_EQ(200, res->status);
@@ -2537,13 +2535,13 @@ TEST_F(ServerTest, SlowPostFail) {
25372535
memset(buffer, 0x42, sizeof(buffer));
25382536

25392537
cli_.set_write_timeout(std::chrono::seconds(0));
2540-
auto res =
2541-
cli_.Post("/slowpost", 64 * 1024 * 1024,
2542-
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2543-
sink.write(buffer, sizeof(buffer));
2544-
return true;
2545-
},
2546-
"text/plain");
2538+
auto res = cli_.Post(
2539+
"/slowpost", 64 * 1024 * 1024,
2540+
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2541+
sink.write(buffer, sizeof(buffer));
2542+
return true;
2543+
},
2544+
"text/plain");
25472545

25482546
ASSERT_TRUE(!res);
25492547
EXPECT_EQ(Error::Write, res.error());
@@ -2557,38 +2555,42 @@ TEST_F(ServerTest, Put) {
25572555
}
25582556

25592557
TEST_F(ServerTest, PutWithContentProvider) {
2560-
auto res = cli_.Put("/put", 3,
2561-
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2562-
EXPECT_TRUE(sink.is_writable());
2563-
sink.os << "PUT";
2564-
return true;
2565-
},
2566-
"text/plain");
2558+
auto res = cli_.Put(
2559+
"/put", 3,
2560+
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2561+
EXPECT_TRUE(sink.is_writable());
2562+
sink.os << "PUT";
2563+
return true;
2564+
},
2565+
"text/plain");
25672566

25682567
ASSERT_TRUE(res);
25692568
EXPECT_EQ(200, res->status);
25702569
EXPECT_EQ("PUT", res->body);
25712570
}
25722571

25732572
TEST_F(ServerTest, PostWithContentProviderAbort) {
2574-
auto res = cli_.Post("/post", 42,
2575-
[](size_t /*offset*/, size_t /*length*/,
2576-
DataSink & /*sink*/) { return false; },
2577-
"text/plain");
2573+
auto res = cli_.Post(
2574+
"/post", 42,
2575+
[](size_t /*offset*/, size_t /*length*/, DataSink & /*sink*/) {
2576+
return false;
2577+
},
2578+
"text/plain");
25782579

25792580
ASSERT_TRUE(!res);
25802581
EXPECT_EQ(Error::Canceled, res.error());
25812582
}
25822583

25832584
TEST_F(ServerTest, PutWithContentProviderWithoutLength) {
2584-
auto res = cli_.Put("/put",
2585-
[](size_t /*offset*/, DataSink &sink) {
2586-
EXPECT_TRUE(sink.is_writable());
2587-
sink.os << "PUT";
2588-
sink.done();
2589-
return true;
2590-
},
2591-
"text/plain");
2585+
auto res = cli_.Put(
2586+
"/put",
2587+
[](size_t /*offset*/, DataSink &sink) {
2588+
EXPECT_TRUE(sink.is_writable());
2589+
sink.os << "PUT";
2590+
sink.done();
2591+
return true;
2592+
},
2593+
"text/plain");
25922594

25932595
ASSERT_TRUE(res);
25942596
EXPECT_EQ(200, res->status);
@@ -2607,13 +2609,14 @@ TEST_F(ServerTest, PostWithContentProviderWithoutLengthAbort) {
26072609
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
26082610
TEST_F(ServerTest, PutWithContentProviderWithGzip) {
26092611
cli_.set_compress(true);
2610-
auto res = cli_.Put("/put", 3,
2611-
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2612-
EXPECT_TRUE(sink.is_writable());
2613-
sink.os << "PUT";
2614-
return true;
2615-
},
2616-
"text/plain");
2612+
auto res = cli_.Put(
2613+
"/put", 3,
2614+
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
2615+
EXPECT_TRUE(sink.is_writable());
2616+
sink.os << "PUT";
2617+
return true;
2618+
},
2619+
"text/plain");
26172620

26182621
ASSERT_TRUE(res);
26192622
EXPECT_EQ(200, res->status);
@@ -2622,25 +2625,28 @@ TEST_F(ServerTest, PutWithContentProviderWithGzip) {
26222625

26232626
TEST_F(ServerTest, PostWithContentProviderWithGzipAbort) {
26242627
cli_.set_compress(true);
2625-
auto res = cli_.Post("/post", 42,
2626-
[](size_t /*offset*/, size_t /*length*/,
2627-
DataSink & /*sink*/) { return false; },
2628-
"text/plain");
2628+
auto res = cli_.Post(
2629+
"/post", 42,
2630+
[](size_t /*offset*/, size_t /*length*/, DataSink & /*sink*/) {
2631+
return false;
2632+
},
2633+
"text/plain");
26292634

26302635
ASSERT_TRUE(!res);
26312636
EXPECT_EQ(Error::Canceled, res.error());
26322637
}
26332638

26342639
TEST_F(ServerTest, PutWithContentProviderWithoutLengthWithGzip) {
26352640
cli_.set_compress(true);
2636-
auto res = cli_.Put("/put",
2637-
[](size_t /*offset*/, DataSink &sink) {
2638-
EXPECT_TRUE(sink.is_writable());
2639-
sink.os << "PUT";
2640-
sink.done();
2641-
return true;
2642-
},
2643-
"text/plain");
2641+
auto res = cli_.Put(
2642+
"/put",
2643+
[](size_t /*offset*/, DataSink &sink) {
2644+
EXPECT_TRUE(sink.is_writable());
2645+
sink.os << "PUT";
2646+
sink.done();
2647+
return true;
2648+
},
2649+
"text/plain");
26442650

26452651
ASSERT_TRUE(res);
26462652
EXPECT_EQ(200, res->status);
@@ -2960,8 +2966,9 @@ TEST_F(ServerTest, KeepAlive) {
29602966
EXPECT_EQ("empty", res->body);
29612967
EXPECT_EQ("close", res->get_header_value("Connection"));
29622968

2963-
res = cli_.Post("/empty", 0, [&](size_t, size_t, DataSink &) { return true; },
2964-
"text/plain");
2969+
res = cli_.Post(
2970+
"/empty", 0, [&](size_t, size_t, DataSink &) { return true; },
2971+
"text/plain");
29652972
ASSERT_TRUE(res);
29662973
EXPECT_EQ(200, res->status);
29672974
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
@@ -3556,7 +3563,7 @@ TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
35563563
TEST(GetWithParametersTest, GetWithParameters) {
35573564
Server svr;
35583565

3559-
svr.Get("/", [&](const Request & req, Response &res) {
3566+
svr.Get("/", [&](const Request &req, Response &res) {
35603567
auto text = req.get_param_value("hello");
35613568
res.set_content(text, "text/plain");
35623569
});
@@ -3585,7 +3592,7 @@ TEST(GetWithParametersTest, GetWithParameters) {
35853592
TEST(GetWithParametersTest, GetWithParameters2) {
35863593
Server svr;
35873594

3588-
svr.Get("/", [&](const Request & req, Response &res) {
3595+
svr.Get("/", [&](const Request &req, Response &res) {
35893596
auto text = req.get_param_value("hello");
35903597
res.set_content(text, "text/plain");
35913598
});
@@ -3602,10 +3609,11 @@ TEST(GetWithParametersTest, GetWithParameters2) {
36023609
params.emplace("hello", "world");
36033610

36043611
std::string body;
3605-
auto res = cli.Get("/", params, Headers{}, [&](const char *data, size_t data_length) {
3606-
body.append(data, data_length);
3607-
return true;
3608-
});
3612+
auto res = cli.Get("/", params, Headers{},
3613+
[&](const char *data, size_t data_length) {
3614+
body.append(data, data_length);
3615+
return true;
3616+
});
36093617

36103618
ASSERT_TRUE(res);
36113619
EXPECT_EQ(200, res->status);

0 commit comments

Comments
 (0)