acl  3.5.3.0
http_server.hpp
浏览该文件的文档.
1 #pragma once
2 
3 #include <string>
5 
6 namespace acl {
7 
8 class http_server : public http_server_impl {
9 public:
10  http_server(const char* addr = "127.0.0.1|6379", bool use_redis = true)
11  : http_server_impl(addr, use_redis) {}
12  ~http_server(void) {}
13 
14 public:
15  http_server& Get(const char* path, http_handler_t fn) {
16  this->Service(http_handler_get, path, fn);
17  return *this;
18  }
19 
20  http_server& Post(const char* path, http_handler_t fn) {
21  this->Service(http_handler_post, path, fn);
22  return *this;
23  }
24 
25  http_server& Head(const char* path, http_handler_t fn) {
26  this->Service(http_handler_head, path, fn);
27  return *this;
28  }
29 
30  http_server& Put(const char* path, http_handler_t fn) {
31  this->Service(http_handler_put, path, fn);
32  return *this;
33  }
34 
35  http_server& Patch(const char* path, http_handler_t fn) {
36  this->Service(http_handler_patch, path, fn);
37  return *this;
38  }
39 
40  http_server& Connect(const char* path, http_handler_t fn) {
41  this->Service(http_handler_connect, path, fn);
42  return *this;
43  }
44 
45  http_server& Purge(const char* path, http_handler_t fn) {
46  this->Service(http_handler_purge, path, fn);
47  return *this;
48  }
49 
50  http_server& Delete(const char* path, http_handler_t fn) {
51  this->Service(http_handler_delete, path, fn);
52  return *this;
53  }
54 
55  http_server& Options(const char* path, http_handler_t fn) {
56  this->Service(http_handler_options, path, fn);
57  return *this;
58  }
59 
60  http_server& Propfind(const char* path, http_handler_t fn) {
61  this->Service(http_handler_profind, path, fn);
62  return *this;
63  }
64 
65  http_server& Websocket(const char* path, http_handler_t fn) {
66  this->Service(http_handler_websocket, path, fn);
67  return *this;
68  }
69 
70  http_server& Unknown(const char* path, http_handler_t fn) {
71  this->Service(http_handler_unknown, path, fn);
72  return *this;
73  }
74 
75  http_server& Error(const char* path, http_handler_t fn) {
76  this->Service(http_handler_error, path, fn);
77  return *this;
78  }
79 
80 public:
82  this->proc_jail_ = fn;
83  return *this;
84  }
85 
87  this->proc_init_ = fn;
88  return *this;
89  }
90 
92  this->proc_exit_ = fn;
93  return *this;
94  }
95 
97  this->proc_sighup_ = fn;
98  return *this;
99  }
100 
102  this->thread_init_ = fn;
103  return *this;
104  }
105 
107  this->thread_accept_ = fn;
108  return *this;
109  }
110 };
111 
112 } // namespace acl
http_server & on_thread_accept(thread_accept_t fn)
std::function< void()> proc_jail_t
http_server & Patch(const char *path, http_handler_t fn)
Definition: http_server.hpp:35
http_server & Post(const char *path, http_handler_t fn)
Definition: http_server.hpp:20
http_server & Get(const char *path, http_handler_t fn)
Definition: http_server.hpp:15
http_server(const char *addr="127.0.0.1|6379", bool use_redis=true)
Definition: http_server.hpp:10
http_server & Delete(const char *path, http_handler_t fn)
Definition: http_server.hpp:50
http_server & Purge(const char *path, http_handler_t fn)
Definition: http_server.hpp:45
std::function< bool(HttpRequest &, HttpResponse &)> http_handler_t
std::function< void()> thread_init_t
std::function< void()> proc_init_t
http_server & Websocket(const char *path, http_handler_t fn)
Definition: http_server.hpp:65
http_server & Options(const char *path, http_handler_t fn)
Definition: http_server.hpp:55
thread_accept_t thread_accept_
http_server & before_proc_jail(proc_jail_t fn)
Definition: http_server.hpp:81
http_server & Propfind(const char *path, http_handler_t fn)
Definition: http_server.hpp:60
http_server & on_thread_init(thread_init_t fn)
http_server & Error(const char *path, http_handler_t fn)
Definition: http_server.hpp:75
void Service(int type, const char *path, http_handler_t fn)
http_server & on_proc_init(proc_init_t fn)
Definition: http_server.hpp:86
http_server & Head(const char *path, http_handler_t fn)
Definition: http_server.hpp:25
http_server & Connect(const char *path, http_handler_t fn)
Definition: http_server.hpp:40
http_server & on_proc_sighup(proc_sighup_t fn)
Definition: http_server.hpp:96
std::function< bool(acl::socket_stream &)> thread_accept_t
http_server & Put(const char *path, http_handler_t fn)
Definition: http_server.hpp:30
http_server & Unknown(const char *path, http_handler_t fn)
Definition: http_server.hpp:70
std::function< bool(acl::string &)> proc_sighup_t
std::function< void()> proc_exit_t
http_server & on_proc_exit(proc_exit_t fn)
Definition: http_server.hpp:91