2020-06-24 16:46:05 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2020-06-24 17:35:37 +08:00
|
|
|
#include "detail/http_server_impl.hpp"
|
2020-06-24 16:46:05 +08:00
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
class http_server : public http_server_impl {
|
|
|
|
public:
|
2020-06-26 21:45:51 +08:00
|
|
|
http_server(const char* addr = "127.0.0.1|6379", bool use_redis = true)
|
|
|
|
: http_server_impl(addr, use_redis) {}
|
2020-06-24 16:46:05 +08:00
|
|
|
~http_server(void) {}
|
|
|
|
|
|
|
|
public:
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Get(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_get, path, fn);
|
2020-06-25 11:58:01 +08:00
|
|
|
return *this;
|
2020-06-24 16:46:05 +08:00
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Post(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_post, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Head(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_head, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Put(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_put, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Patch(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_patch, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Connect(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_connect, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Purge(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_purge, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Delete(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_delete, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Options(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_options, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Propfind(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_profind, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Error(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_error, path, fn);
|
2020-06-26 15:21:13 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:33:31 +08:00
|
|
|
http_server& Websocket(const char* path, http_handler_t fn) {
|
2020-06-26 15:34:55 +08:00
|
|
|
this->Service(http_handler_websocket, path, fn);
|
2020-06-25 11:58:01 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
http_server& before_proc_jail(proc_jail_t fn) {
|
|
|
|
this->proc_jail_ = fn;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_server& on_proc_init(proc_init_t fn) {
|
|
|
|
this->proc_init_ = fn;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_server& on_proc_exit(proc_exit_t fn) {
|
|
|
|
this->proc_exit_ = fn;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_server& on_proc_sighup(proc_sighup_t fn) {
|
|
|
|
this->proc_sighup_ = fn;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_server& on_thread_init(thread_init_t fn) {
|
|
|
|
this->thread_init_ = fn;
|
|
|
|
return *this;
|
2020-06-24 16:46:05 +08:00
|
|
|
}
|
2020-06-26 10:33:10 +08:00
|
|
|
|
|
|
|
http_server& on_thread_accept(thread_accept_t fn) {
|
|
|
|
this->thread_accept_ = fn;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-06-24 16:46:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|