Apply clangformat

This commit is contained in:
Yuji Hirose 2019-04-11 08:13:31 -04:00
parent a91a0b7dbf
commit 5d082f1da4
6 changed files with 2833 additions and 2970 deletions

View File

@ -10,8 +10,7 @@
using namespace std;
int main(void)
{
int main(void) {
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
httplib::SSLClient cli("localhost", 8080);
#else

View File

@ -8,8 +8,7 @@
#include <httplib.h>
using namespace httplib;
int main(void)
{
int main(void) {
Server svr;
svr.Get("/hi", [](const Request & /*req*/, Response &res) {

View File

@ -5,17 +5,16 @@
// The Boost Software License 1.0
//
#include <httplib.h>
#include <cstdio>
#include <chrono>
#include <cstdio>
#include <httplib.h>
#define SERVER_CERT_FILE "./cert.pem"
#define SERVER_PRIVATE_KEY_FILE "./key.pem"
using namespace httplib;
std::string dump_headers(const Headers& headers)
{
std::string dump_headers(const Headers &headers) {
std::string s;
char buf[BUFSIZ];
@ -28,21 +27,22 @@ std::string dump_headers(const Headers& headers)
return s;
}
std::string log(const Request& req, const Response& res)
{
std::string log(const Request &req, const Response &res) {
std::string s;
char buf[BUFSIZ];
s += "================================\n";
snprintf(buf, sizeof(buf), "%s %s %s", req.method.c_str(), req.version.c_str(), req.path.c_str());
snprintf(buf, sizeof(buf), "%s %s %s", req.method.c_str(),
req.version.c_str(), req.path.c_str());
s += buf;
std::string query;
for (auto it = req.params.begin(); it != req.params.end(); ++it) {
const auto &x = *it;
snprintf(buf, sizeof(buf), "%c%s=%s",
(it == req.params.begin()) ? '?' : '&', x.first.c_str(), x.second.c_str());
(it == req.params.begin()) ? '?' : '&', x.first.c_str(),
x.second.c_str());
query += buf;
}
snprintf(buf, sizeof(buf), "%s\n", query.c_str());
@ -57,17 +57,14 @@ std::string log(const Request& req, const Response& res)
s += dump_headers(res.headers);
s += "\n";
if (!res.body.empty()) {
s += res.body;
}
if (!res.body.empty()) { s += res.body; }
s += "\n";
return s;
}
int main(void)
{
int main(void) {
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
#else
@ -96,9 +93,8 @@ int main(void)
res.set_content(dump_headers(req.headers), "text/plain");
});
svr.Get("/stop", [&](const Request& /*req*/, Response& /*res*/) {
svr.stop();
});
svr.Get("/stop",
[&](const Request & /*req*/, Response & /*res*/) { svr.stop(); });
svr.set_error_handler([](const Request & /*req*/, Response &res) {
const char *fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";

View File

@ -5,8 +5,8 @@
// The Boost Software License 1.0
//
#include <httplib.h>
#include <cstdio>
#include <httplib.h>
#include <iostream>
#define SERVER_CERT_FILE "./cert.pem"
@ -15,8 +15,7 @@
using namespace httplib;
using namespace std;
string dump_headers(const Headers& headers)
{
string dump_headers(const Headers &headers) {
string s;
char buf[BUFSIZ];
@ -28,8 +27,7 @@ string dump_headers(const Headers& headers)
return s;
}
string dump_multipart_files(const MultipartFiles& files)
{
string dump_multipart_files(const MultipartFiles &files) {
string s;
char buf[BUFSIZ];
@ -60,21 +58,22 @@ string dump_multipart_files(const MultipartFiles& files)
return s;
}
string log(const Request& req, const Response& res)
{
string log(const Request &req, const Response &res) {
string s;
char buf[BUFSIZ];
s += "================================\n";
snprintf(buf, sizeof(buf), "%s %s %s", req.method.c_str(), req.version.c_str(), req.path.c_str());
snprintf(buf, sizeof(buf), "%s %s %s", req.method.c_str(),
req.version.c_str(), req.path.c_str());
s += buf;
string query;
for (auto it = req.params.begin(); it != req.params.end(); ++it) {
const auto &x = *it;
snprintf(buf, sizeof(buf), "%c%s=%s",
(it == req.params.begin()) ? '?' : '&', x.first.c_str(), x.second.c_str());
(it == req.params.begin()) ? '?' : '&', x.first.c_str(),
x.second.c_str());
query += buf;
}
snprintf(buf, sizeof(buf), "%s\n", query.c_str());
@ -92,8 +91,7 @@ string log(const Request& req, const Response& res)
return s;
}
int main(int argc, const char** argv)
{
int main(int argc, const char **argv) {
if (argc > 1 && string("--help") == argv[1]) {
cout << "usage: simplesvr [PORT] [DIR]" << endl;
return 1;
@ -106,9 +104,7 @@ int main(int argc, const char** argv)
#endif
svr.Post("/multipart", [](const Request &req, Response &res) {
auto body =
dump_headers(req.headers) +
dump_multipart_files(req.files);
auto body = dump_headers(req.headers) + dump_multipart_files(req.files);
res.set_content(body, "text/plain");
});
@ -120,19 +116,14 @@ int main(int argc, const char** argv)
res.set_content(buf, "text/html");
});
svr.set_logger([](const Request& req, const Response& res) {
cout << log(req, res);
});
svr.set_logger(
[](const Request &req, const Response &res) { cout << log(req, res); });
auto port = 8080;
if (argc > 1) {
port = atoi(argv[1]);
}
if (argc > 1) { port = atoi(argv[1]); }
auto base_dir = "./";
if (argc > 2) {
base_dir = argv[2];
}
if (argc > 2) { base_dir = argv[2]; }
svr.set_base_dir(base_dir);

952
httplib.h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff