mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Refactoring.
This commit is contained in:
parent
17bf14a2f7
commit
1d0b3504bd
2 changed files with 33 additions and 29 deletions
|
@ -70,12 +70,10 @@ int main(void)
|
|||
{
|
||||
using namespace httplib;
|
||||
|
||||
const char* hi = "/hi";
|
||||
|
||||
Server svr("localhost", 8080);
|
||||
|
||||
svr.get("/", [=](Connection& c) {
|
||||
c.response.set_redirect(hi);
|
||||
c.response.set_redirect("/hi");
|
||||
});
|
||||
|
||||
svr.get("/hi", [](Connection& c) {
|
||||
|
@ -86,9 +84,10 @@ int main(void)
|
|||
c.response.set_content(dump_headers(c.request.headers), "text/plain");
|
||||
});
|
||||
|
||||
svr.set_error_handler([](httplib::Connection& c) {
|
||||
svr.set_error_handler([](Connection& c) {
|
||||
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
|
||||
char buf[BUFSIZ];
|
||||
snprintf(buf, sizeof(buf), "<p>Error Status: <span style='color:red;'>%d</span></p>", c.response.status);
|
||||
snprintf(buf, sizeof(buf), fmt, c.response.status);
|
||||
c.response.set_content(buf, "text/html");
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue