mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Code refactoring.
This commit is contained in:
parent
34f71312e8
commit
42473b722f
3 changed files with 85 additions and 77 deletions
|
@ -57,13 +57,20 @@ std::string log(const httplib::Connection& c)
|
|||
return s;
|
||||
}
|
||||
|
||||
inline void error_handler(httplib::Connection& c)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
snprintf(buf, sizeof(buf), "Error Status: %d\r\n", c.response.status);
|
||||
c.response.set_content(buf);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
using namespace httplib;
|
||||
|
||||
const char* hi = "/hi";
|
||||
|
||||
Server svr("localhost", 1234);
|
||||
Server svr("localhost", 8080);
|
||||
|
||||
svr.get("/", [=](Connection& c) {
|
||||
c.response.set_redirect(hi);
|
||||
|
@ -74,9 +81,11 @@ int main(void)
|
|||
});
|
||||
|
||||
svr.get("/dump", [](Connection& c) {
|
||||
c.response.set_content(log(c));
|
||||
c.response.set_content(httplib::dump_headers(c.request.headers));
|
||||
});
|
||||
|
||||
svr.error(error_handler);
|
||||
|
||||
svr.set_logger([](const Connection& c) {
|
||||
printf("%s", log(c).c_str());
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue