Skip to content

Commit 0d527e2

Browse files
committed
Code formatting
1 parent bea3ebd commit 0d527e2

File tree

2 files changed

+61
-57
lines changed

2 files changed

+61
-57
lines changed

httplib.h

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#define CPPHTTPLIB_THREAD_POOL_COUNT 8
5353
#endif
5454

55+
/*
56+
* Headers
57+
*/
58+
5559
#ifdef _WIN32
5660
#ifndef _CRT_SECURE_NO_WARNINGS
5761
#define _CRT_SECURE_NO_WARNINGS
@@ -61,10 +65,6 @@
6165
#define _CRT_NONSTDC_NO_DEPRECATE
6266
#endif //_CRT_NONSTDC_NO_DEPRECATE
6367

64-
/*
65-
* Headers
66-
*/
67-
6868
#if defined(_MSC_VER)
6969
#ifdef _WIN64
7070
typedef __int64 ssize_t;
@@ -589,37 +589,45 @@ class Client {
589589
std::shared_ptr<Response> Head(const char *path, const Headers &headers);
590590

591591
std::shared_ptr<Response> Post(const char *path, const std::string &body,
592-
const char *content_type, bool compress = false);
592+
const char *content_type,
593+
bool compress = false);
593594

594595
std::shared_ptr<Response> Post(const char *path, const Headers &headers,
595596
const std::string &body,
596597
const char *content_type,
597598
bool compress = false);
598599

599-
std::shared_ptr<Response> Post(const char *path, const Params &params, bool compress = false);
600+
std::shared_ptr<Response> Post(const char *path, const Params &params,
601+
bool compress = false);
600602

601603
std::shared_ptr<Response> Post(const char *path, const Headers &headers,
602604
const Params &params, bool compress = false);
603605

604606
std::shared_ptr<Response> Post(const char *path,
605-
const MultipartFormDataItems &items, bool compress = false);
607+
const MultipartFormDataItems &items,
608+
bool compress = false);
606609

607610
std::shared_ptr<Response> Post(const char *path, const Headers &headers,
608-
const MultipartFormDataItems &items, bool compress = false);
611+
const MultipartFormDataItems &items,
612+
bool compress = false);
609613

610614
std::shared_ptr<Response> Put(const char *path, const std::string &body,
611-
const char *content_type, bool compress = false);
615+
const char *content_type,
616+
bool compress = false);
612617

613618
std::shared_ptr<Response> Put(const char *path, const Headers &headers,
614619
const std::string &body,
615-
const char *content_type, bool compress = false);
620+
const char *content_type,
621+
bool compress = false);
616622

617623
std::shared_ptr<Response> Patch(const char *path, const std::string &body,
618-
const char *content_type, bool compress = false);
624+
const char *content_type,
625+
bool compress = false);
619626

620627
std::shared_ptr<Response> Patch(const char *path, const Headers &headers,
621628
const std::string &body,
622-
const char *content_type, bool compress = false);
629+
const char *content_type,
630+
bool compress = false);
623631

624632
std::shared_ptr<Response> Delete(const char *path);
625633

@@ -3120,14 +3128,14 @@ inline std::shared_ptr<Response> Client::Head(const char *path,
31203128

31213129
inline std::shared_ptr<Response> Client::Post(const char *path,
31223130
const std::string &body,
3123-
const char *content_type, bool compress) {
3131+
const char *content_type,
3132+
bool compress) {
31243133
return Post(path, Headers(), body, content_type, compress);
31253134
}
31263135

3127-
inline std::shared_ptr<Response> Client::Post(const char *path,
3128-
const Headers &headers,
3129-
const std::string &body,
3130-
const char *content_type, bool compress) {
3136+
inline std::shared_ptr<Response>
3137+
Client::Post(const char *path, const Headers &headers, const std::string &body,
3138+
const char *content_type, bool compress) {
31313139
Request req;
31323140
req.method = "POST";
31333141
req.headers = headers;
@@ -3137,9 +3145,7 @@ inline std::shared_ptr<Response> Client::Post(const char *path,
31373145
req.body = body;
31383146

31393147
if (compress) {
3140-
if (!detail::compress(req.body)) {
3141-
return nullptr;
3142-
}
3148+
if (!detail::compress(req.body)) { return nullptr; }
31433149
req.headers.emplace("Content-Encoding", "gzip");
31443150
}
31453151

@@ -3148,13 +3154,15 @@ inline std::shared_ptr<Response> Client::Post(const char *path,
31483154
return send(req, *res) ? res : nullptr;
31493155
}
31503156

3151-
inline std::shared_ptr<Response> Client::Post(const char *path,
3152-
const Params &params, bool compress) {
3157+
inline std::shared_ptr<Response>
3158+
Client::Post(const char *path, const Params &params, bool compress) {
31533159
return Post(path, Headers(), params, compress);
31543160
}
31553161

3156-
inline std::shared_ptr<Response>
3157-
Client::Post(const char *path, const Headers &headers, const Params &params, bool compress) {
3162+
inline std::shared_ptr<Response> Client::Post(const char *path,
3163+
const Headers &headers,
3164+
const Params &params,
3165+
bool compress) {
31583166
std::string query;
31593167
for (auto it = params.begin(); it != params.end(); ++it) {
31603168
if (it != params.begin()) { query += "&"; }
@@ -3163,11 +3171,13 @@ Client::Post(const char *path, const Headers &headers, const Params &params, boo
31633171
query += detail::encode_url(it->second);
31643172
}
31653173

3166-
return Post(path, headers, query, "application/x-www-form-urlencoded", compress);
3174+
return Post(path, headers, query, "application/x-www-form-urlencoded",
3175+
compress);
31673176
}
31683177

31693178
inline std::shared_ptr<Response>
3170-
Client::Post(const char *path, const MultipartFormDataItems &items, bool compress) {
3179+
Client::Post(const char *path, const MultipartFormDataItems &items,
3180+
bool compress) {
31713181
return Post(path, Headers(), items, compress);
31723182
}
31733183

@@ -3205,11 +3215,9 @@ inline std::shared_ptr<Response> Client::Put(const char *path,
32053215
return Put(path, Headers(), body, content_type, compress);
32063216
}
32073217

3208-
inline std::shared_ptr<Response> Client::Put(const char *path,
3209-
const Headers &headers,
3210-
const std::string &body,
3211-
const char *content_type,
3212-
bool compress) {
3218+
inline std::shared_ptr<Response>
3219+
Client::Put(const char *path, const Headers &headers, const std::string &body,
3220+
const char *content_type, bool compress) {
32133221
Request req;
32143222
req.method = "PUT";
32153223
req.headers = headers;
@@ -3219,9 +3227,7 @@ inline std::shared_ptr<Response> Client::Put(const char *path,
32193227
req.body = body;
32203228

32213229
if (compress) {
3222-
if (!detail::compress(req.body)) {
3223-
return nullptr;
3224-
}
3230+
if (!detail::compress(req.body)) { return nullptr; }
32253231
req.headers.emplace("Content-Encoding", "gzip");
32263232
}
32273233

@@ -3237,11 +3243,9 @@ inline std::shared_ptr<Response> Client::Patch(const char *path,
32373243
return Patch(path, Headers(), body, content_type, compress);
32383244
}
32393245

3240-
inline std::shared_ptr<Response> Client::Patch(const char *path,
3241-
const Headers &headers,
3242-
const std::string &body,
3243-
const char *content_type,
3244-
bool compress) {
3246+
inline std::shared_ptr<Response>
3247+
Client::Patch(const char *path, const Headers &headers, const std::string &body,
3248+
const char *content_type, bool compress) {
32453249
Request req;
32463250
req.method = "PATCH";
32473251
req.headers = headers;
@@ -3251,9 +3255,7 @@ inline std::shared_ptr<Response> Client::Patch(const char *path,
32513255
req.body = body;
32523256

32533257
if (compress) {
3254-
if (!detail::compress(req.body)) {
3255-
return nullptr;
3256-
}
3258+
if (!detail::compress(req.body)) { return nullptr; }
32573259
req.headers.emplace("Content-Encoding", "gzip");
32583260
}
32593261

test/test.cc

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,16 @@ TEST(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {
255255
#endif
256256

257257
std::string body;
258-
auto res =
259-
cli.Get("/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137", Headers(),
260-
[&](const Response& response) {
261-
EXPECT_EQ(200, response.status);
262-
return true;
263-
},
264-
[&](const char *data, size_t data_length, uint64_t, uint64_t) {
265-
body.append(data, data_length);
266-
return true;
267-
});
258+
auto res = cli.Get(
259+
"/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137", Headers(),
260+
[&](const Response &response) {
261+
EXPECT_EQ(200, response.status);
262+
return true;
263+
},
264+
[&](const char *data, size_t data_length, uint64_t, uint64_t) {
265+
body.append(data, data_length);
266+
return true;
267+
});
268268
ASSERT_TRUE(res != nullptr);
269269

270270
std::string out;
@@ -539,7 +539,8 @@ TEST(YahooRedirectTest, Redirect) {
539539
TEST(HttpsToHttpRedirectTest, Redirect) {
540540
httplib::SSLClient cli("httpbin.org");
541541
cli.follow_location(true);
542-
auto res = cli.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
542+
auto res =
543+
cli.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
543544
ASSERT_TRUE(res != nullptr);
544545
}
545546
#endif
@@ -636,7 +637,8 @@ class ServerTest : public ::testing::Test {
636637
[data](uint64_t offset, uint64_t length, DataSink sink) {
637638
size_t DATA_CHUNK_SIZE = 4;
638639
const auto &d = *data;
639-
auto out_len = std::min(static_cast<size_t>(length), DATA_CHUNK_SIZE);
640+
auto out_len =
641+
std::min(static_cast<size_t>(length), DATA_CHUNK_SIZE);
640642
sink(&d[static_cast<size_t>(offset)], out_len);
641643
},
642644
[data] { delete data; });
@@ -1422,19 +1424,19 @@ TEST_F(ServerTest, KeepAlive) {
14221424
ASSERT_TRUE(requests.size() == responses.size());
14231425

14241426
for (int i = 0; i < 3; i++) {
1425-
auto& res = responses[i];
1427+
auto &res = responses[i];
14261428
EXPECT_EQ(200, res.status);
14271429
EXPECT_EQ("text/plain", res.get_header_value("Content-Type"));
14281430
EXPECT_EQ("Hello World!", res.body);
14291431
}
14301432

14311433
{
1432-
auto& res = responses[3];
1434+
auto &res = responses[3];
14331435
EXPECT_EQ(404, res.status);
14341436
}
14351437

14361438
{
1437-
auto& res = responses[4];
1439+
auto &res = responses[4];
14381440
EXPECT_EQ(200, res.status);
14391441
EXPECT_EQ("text/plain", res.get_header_value("Content-Type"));
14401442
EXPECT_EQ("empty", res.body);

0 commit comments

Comments
 (0)