mirror of
https://github.com/lammertb/libhttp.git
synced 2025-07-03 06:22:34 +03:00
@ -26,9 +26,9 @@ public:
|
||||
mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
||||
mg_printf(conn, "<html><body>\r\n");
|
||||
mg_printf(conn, "<h2>This is an example text from a C++ handler</h2>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the A handler <a href=\"A\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the A handler with a parameter <a href=\"A?param=1\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the A/B handler <a href=\"A/B\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the A handler <a href=\"a\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the A handler with a parameter <a href=\"a?param=1\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the A/B handler <a href=\"a/b\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To see a page from the *.foo handler <a href=\"xy.foo\">click here</a></p>\r\n");
|
||||
mg_printf(conn, "<p>To exit <a href=\"%s\">click here</a></p>\r\n", EXIT_URI);
|
||||
mg_printf(conn, "</body></html>\r\n");
|
||||
@ -111,11 +111,20 @@ int main(int argc, char *argv[])
|
||||
|
||||
CivetServer server(options);
|
||||
|
||||
server.addHandler(EXAMPLE_URI, new ExampleHandler());
|
||||
server.addHandler(EXIT_URI, new ExitHandler());
|
||||
server.addHandler("/a", new AHandler());
|
||||
server.addHandler("/a/b", new ABHandler());
|
||||
server.addHandler("**.foo$", new FooHandler());
|
||||
ExampleHandler h_ex;
|
||||
server.addHandler(EXAMPLE_URI, h_ex);
|
||||
|
||||
ExitHandler h_exit;
|
||||
server.addHandler(EXIT_URI, h_exit);
|
||||
|
||||
AHandler h_a;
|
||||
server.addHandler("/a", h_a);
|
||||
|
||||
ABHandler h_ab;
|
||||
server.addHandler("/a/b", h_ab);
|
||||
|
||||
FooHandler h_foo;
|
||||
server.addHandler("**.foo$", h_foo);
|
||||
|
||||
printf("Browse files at http://localhost:%s/\n", PORT);
|
||||
printf("Run example at http://localhost:%s%s\n", PORT, EXAMPLE_URI);
|
||||
|
@ -139,11 +139,14 @@ public:
|
||||
* URI's are ordered and prefix (REST) URI's are supported.
|
||||
*
|
||||
* @param uri - URI to match.
|
||||
* @param handler - handler instance to use. This will be free'ed
|
||||
* when the server closes and instances cannot be reused.
|
||||
* @param handler - handler instance to use.
|
||||
*/
|
||||
void addHandler(const std::string &uri, CivetHandler *handler);
|
||||
|
||||
void addHandler(const std::string &uri, CivetHandler &handler) {
|
||||
addHandler(uri, &handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* removeHandler(const std::string &)
|
||||
*
|
||||
|
Reference in New Issue
Block a user