Skip to content

Commit c30268d

Browse files
committed
Run clang-format
1 parent a3f87f4 commit c30268d

File tree

2 files changed

+30
-46
lines changed

2 files changed

+30
-46
lines changed

httplib.h

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ ssize_t send_socket(socket_t sock, const void *ptr, size_t size, int flags);
24492449

24502450
ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags);
24512451

2452-
enum class EncodingType { None = 0, Gzip, Brotli, Zstd};
2452+
enum class EncodingType { None = 0, Gzip, Brotli, Zstd };
24532453

24542454
EncodingType encoding_type(const Request &req, const Response &res);
24552455

@@ -4201,63 +4201,49 @@ inline zstd_compressor::zstd_compressor() {
42014201
ZSTD_CCtx_setParameter(ctx_, ZSTD_c_compressionLevel, ZSTD_fast);
42024202
}
42034203

4204-
inline zstd_compressor::~zstd_compressor() {
4205-
ZSTD_freeCCtx(ctx_);
4206-
}
4204+
inline zstd_compressor::~zstd_compressor() { ZSTD_freeCCtx(ctx_); }
42074205

42084206
inline bool zstd_compressor::compress(const char *data, size_t data_length,
42094207
bool last, Callback callback) {
42104208
std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};
42114209

42124210
ZSTD_EndDirective mode = last ? ZSTD_e_end : ZSTD_e_continue;
4213-
ZSTD_inBuffer input = { data, data_length, 0 };
4211+
ZSTD_inBuffer input = {data, data_length, 0};
42144212

42154213
bool finished;
42164214
do {
4217-
ZSTD_outBuffer output = { buff.data(), CPPHTTPLIB_COMPRESSION_BUFSIZ, 0 };
4215+
ZSTD_outBuffer output = {buff.data(), CPPHTTPLIB_COMPRESSION_BUFSIZ, 0};
42184216
size_t const remaining = ZSTD_compressStream2(ctx_, &output, &input, mode);
42194217

4220-
if (ZSTD_isError(remaining)) {
4221-
return false;
4222-
}
4218+
if (ZSTD_isError(remaining)) { return false; }
42234219

4224-
if (!callback(buff.data(), output.pos)) {
4225-
return false;
4226-
}
4220+
if (!callback(buff.data(), output.pos)) { return false; }
42274221

42284222
finished = last ? (remaining == 0) : (input.pos == input.size);
42294223

4230-
} while(!finished);
4224+
} while (!finished);
42314225

42324226
return true;
42334227
}
42344228

4235-
inline zstd_decompressor::zstd_decompressor() {
4236-
ctx_ = ZSTD_createDCtx();
4237-
}
4229+
inline zstd_decompressor::zstd_decompressor() { ctx_ = ZSTD_createDCtx(); }
42384230

4239-
inline zstd_decompressor::~zstd_decompressor() {
4240-
ZSTD_freeDCtx(ctx_);
4241-
}
4231+
inline zstd_decompressor::~zstd_decompressor() { ZSTD_freeDCtx(ctx_); }
42424232

42434233
inline bool zstd_decompressor::is_valid() const { return ctx_ != nullptr; }
42444234

42454235
inline bool zstd_decompressor::decompress(const char *data, size_t data_length,
42464236
Callback callback) {
42474237
std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};
4248-
ZSTD_inBuffer input = { data, data_length, 0 };
4238+
ZSTD_inBuffer input = {data, data_length, 0};
42494239

42504240
while (input.pos < input.size) {
4251-
ZSTD_outBuffer output = { buff.data(), CPPHTTPLIB_COMPRESSION_BUFSIZ, 0 };
4252-
size_t const remaining = ZSTD_decompressStream(ctx_, &output , &input);
4241+
ZSTD_outBuffer output = {buff.data(), CPPHTTPLIB_COMPRESSION_BUFSIZ, 0};
4242+
size_t const remaining = ZSTD_decompressStream(ctx_, &output, &input);
42534243

4254-
if (ZSTD_isError(remaining)) {
4255-
return false;
4256-
}
4244+
if (ZSTD_isError(remaining)) { return false; }
42574245

4258-
if (!callback(buff.data(), output.pos)) {
4259-
return false;
4260-
}
4246+
if (!callback(buff.data(), output.pos)) { return false; }
42614247
}
42624248

42634249
return true;
@@ -10506,4 +10492,4 @@ inline SSL_CTX *Client::ssl_context() const {
1050610492

1050710493
} // namespace httplib
1050810494

10509-
#endif // CPPHTTPLIB_HTTPLIB_H
10495+
#endif // CPPHTTPLIB_HTTPLIB_H

test/test.cc

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ TEST(ParseAcceptEncoding2, AcceptEncoding) {
688688

689689
TEST(ParseAcceptEncoding3, AcceptEncoding) {
690690
Request req;
691-
req.set_header("Accept-Encoding", "br;q=1.0, gzip;q=0.8, zstd;q=0.8, *;q=0.1");
691+
req.set_header("Accept-Encoding",
692+
"br;q=1.0, gzip;q=0.8, zstd;q=0.8, *;q=0.1");
692693

693694
Response res;
694695
res.set_header("Content-Type", "text/plain");
@@ -3011,7 +3012,8 @@ class ServerTest : public ::testing::Test {
30113012
const httplib::ContentReader &) {
30123013
res.set_content("ok", "text/plain");
30133014
})
3014-
#if defined(CPPHTTPLIB_ZLIB_SUPPORT) || defined(CPPHTTPLIB_BROTLI_SUPPORT) || defined(CPPHTTPLIB_ZSTD_SUPPORT)
3015+
#if defined(CPPHTTPLIB_ZLIB_SUPPORT) || defined(CPPHTTPLIB_BROTLI_SUPPORT) || \
3016+
defined(CPPHTTPLIB_ZSTD_SUPPORT)
30153017
.Get("/compress",
30163018
[&](const Request & /*req*/, Response &res) {
30173019
res.set_content(
@@ -4991,20 +4993,19 @@ TEST_F(ServerTest, ZstdWithoutDecompressing) {
49914993
cli_.set_decompress(false);
49924994
auto res = cli_.Get("/compress", headers);
49934995

4994-
unsigned char compressed[26] = {
4995-
0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x64, 0x8d, 0x00,
4996-
0x00, 0x50, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
4997-
0x37, 0x38, 0x39, 0x30, 0x01, 0x00, 0xd7, 0xa9,
4998-
0x20, 0x01
4999-
};
4996+
unsigned char compressed[26] = {0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x64, 0x8d,
4997+
0x00, 0x00, 0x50, 0x31, 0x32, 0x33, 0x34,
4998+
0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x01,
4999+
0x00, 0xd7, 0xa9, 0x20, 0x01};
50005000

50015001
ASSERT_TRUE(res);
50025002
EXPECT_EQ("zstd", res->get_header_value("Content-Encoding"));
50035003
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
50045004
EXPECT_EQ("26", res->get_header_value("Content-Length"));
50055005
EXPECT_EQ(StatusCode::OK_200, res->status);
50065006
ASSERT_EQ(26U, res->body.size());
5007-
EXPECT_TRUE(std::memcmp(compressed, res->body.data(), sizeof(compressed)) == 0);
5007+
EXPECT_TRUE(std::memcmp(compressed, res->body.data(), sizeof(compressed)) ==
5008+
0);
50085009
}
50095010

50105011
TEST_F(ServerTest, ZstdWithContentReceiverWithoutAcceptEncoding) {
@@ -5074,7 +5075,6 @@ TEST_F(ServerTest, MultipartFormDataZstd) {
50745075
Headers headers;
50755076
headers.emplace("Accept-Encoding", "zstd");
50765077

5077-
50785078
cli_.set_compress(true);
50795079
auto res = cli_.Post("/compress-multipart", headers, items);
50805080

@@ -5085,7 +5085,7 @@ TEST_F(ServerTest, MultipartFormDataZstd) {
50855085
TEST_F(ServerTest, PutWithContentProviderWithZstd) {
50865086
Headers headers;
50875087
headers.emplace("Accept-Encoding", "zstd");
5088-
5088+
50895089
cli_.set_compress(true);
50905090
auto res = cli_.Put(
50915091
"/put", headers, 3,
@@ -5148,12 +5148,10 @@ TEST(ZstdDecompressor, ChunkedDecompression) {
51485148

51495149
TEST(ZstdDecompressor, Decompress) {
51505150
std::string original_text = "Compressed with ZSTD";
5151-
unsigned char data[29] = {
5152-
0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x14, 0xa1, 0x00,
5153-
0x00, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73,
5154-
0x73, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68,
5155-
0x20, 0x5a, 0x53, 0x54, 0x44
5156-
};
5151+
unsigned char data[29] = {0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x14, 0xa1, 0x00,
5152+
0x00, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73,
5153+
0x73, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68,
5154+
0x20, 0x5a, 0x53, 0x54, 0x44};
51575155
std::string compressed_data(data, data + sizeof(data) / sizeof(data[0]));
51585156

51595157
std::string decompressed_data;

0 commit comments

Comments
 (0)