diff --git a/examples/embedded_cpp/embedded_cpp.cpp b/examples/embedded_cpp/embedded_cpp.cpp index 3ada0ad5..07c5df96 100644 --- a/examples/embedded_cpp/embedded_cpp.cpp +++ b/examples/embedded_cpp/embedded_cpp.cpp @@ -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, "
\r\n"); mg_printf(conn, "To see a page from the A handler click here
\r\n"); - mg_printf(conn, "To see a page from the A handler with a parameter click here
\r\n"); - mg_printf(conn, "To see a page from the A/B handler click here
\r\n"); + mg_printf(conn, "To see a page from the A handler click here
\r\n"); + mg_printf(conn, "To see a page from the A handler with a parameter click here
\r\n"); + mg_printf(conn, "To see a page from the A/B handler click here
\r\n"); mg_printf(conn, "To see a page from the *.foo handler click here
\r\n"); mg_printf(conn, "To exit click here
\r\n", EXIT_URI); mg_printf(conn, "\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); diff --git a/include/CivetServer.h b/include/CivetServer.h index e1796b3b..d261a0bb 100644 --- a/include/CivetServer.h +++ b/include/CivetServer.h @@ -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 &) * @@ -160,7 +163,7 @@ public: * * @return A vector of ports */ - + std::vector