mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
parent
e46cc54d13
commit
6c5d0b2a18
8 changed files with 255 additions and 103 deletions
|
@ -25,7 +25,7 @@ int main(void) {
|
|||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
StopWatch sw(to_string(i).c_str());
|
||||
auto res = cli.post("/post", body, "application/octet-stream");
|
||||
auto res = cli.Post("/post", body, "application/octet-stream");
|
||||
assert(res->status == 200);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ int main(void)
|
|||
httplib::Client cli("localhost", 8080);
|
||||
#endif
|
||||
|
||||
auto res = cli.get("/hi");
|
||||
auto res = cli.Get("/hi");
|
||||
if (res) {
|
||||
cout << res->status << endl;
|
||||
cout << res->get_header_value("Content-Type") << endl;
|
||||
|
|
|
@ -12,7 +12,7 @@ int main(void)
|
|||
{
|
||||
Server svr;
|
||||
|
||||
svr.get("/hi", [](const auto& /*req*/, auto& res) {
|
||||
svr.Get("/hi", [](const auto& /*req*/, auto& res) {
|
||||
res.set_content("Hello World!", "text/plain");
|
||||
});
|
||||
|
||||
|
|
|
@ -81,25 +81,25 @@ int main(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
svr.get("/", [=](const auto& /*req*/, auto& res) {
|
||||
svr.Get("/", [=](const auto& /*req*/, auto& res) {
|
||||
res.set_redirect("/hi");
|
||||
});
|
||||
|
||||
svr.get("/hi", [](const auto& /*req*/, auto& res) {
|
||||
svr.Get("/hi", [](const auto& /*req*/, auto& res) {
|
||||
res.set_content("Hello World!\n", "text/plain");
|
||||
});
|
||||
|
||||
svr.get("/slow", [](const auto& /*req*/, auto& res) {
|
||||
svr.Get("/slow", [](const auto& /*req*/, auto& res) {
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(2s);
|
||||
res.set_content("Slow...\n", "text/plain");
|
||||
});
|
||||
|
||||
svr.get("/dump", [](const auto& req, auto& res) {
|
||||
svr.Get("/dump", [](const auto& req, auto& res) {
|
||||
res.set_content(dump_headers(req.headers), "text/plain");
|
||||
});
|
||||
|
||||
svr.get("/stop", [&](const auto& /*req*/, auto& /*res*/) {
|
||||
svr.Get("/stop", [&](const auto& /*req*/, auto& /*res*/) {
|
||||
svr.stop();
|
||||
});
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ int main(int argc, const char** argv)
|
|||
Server svr(version);
|
||||
#endif
|
||||
|
||||
svr.post("/multipart", [](const auto& req, auto& res) {
|
||||
svr.Post("/multipart", [](const auto& req, auto& res) {
|
||||
auto body =
|
||||
dump_headers(req.headers) +
|
||||
dump_multipart_files(req.files);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue