|
@@ -1,5 +1,6 @@
|
|
|
#include <httpserver.hpp>
|
|
|
#include <cstdlib>
|
|
|
+#include <memory>
|
|
|
|
|
|
#define PATH "/plaintext"
|
|
|
#define BODY "Hello, World!"
|
|
@@ -8,15 +9,18 @@ using namespace httpserver;
|
|
|
|
|
|
class hello_world_resource : public http_resource {
|
|
|
public:
|
|
|
- const http_response render(const http_request&);
|
|
|
-};
|
|
|
+ hello_world_resource(const std::shared_ptr<http_response>& resp):
|
|
|
+ resp(resp)
|
|
|
+ {
|
|
|
+ }
|
|
|
|
|
|
-const http_response hello_world_resource::render(const http_request& req)
|
|
|
-{
|
|
|
- http_response_builder hrb(BODY, 200);
|
|
|
- hrb.with_header("Server", "libhttpserver");
|
|
|
- return hrb.string_response();
|
|
|
-}
|
|
|
+ const std::shared_ptr<http_response> render(const http_request&) {
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+ std::shared_ptr<http_response> resp;
|
|
|
+};
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
{
|
|
@@ -24,7 +28,10 @@ int main(int argc, char** argv)
|
|
|
.start_method(http::http_utils::INTERNAL_SELECT)
|
|
|
.max_threads(atoi(argv[2]));
|
|
|
|
|
|
- hello_world_resource hwr;
|
|
|
+ std::shared_ptr<http_response> hello = std::shared_ptr<http_response>(new string_response(BODY, 200));
|
|
|
+ hello->with_header("Server", "libhttpserver");
|
|
|
+
|
|
|
+ hello_world_resource hwr(hello);
|
|
|
ws.register_resource(PATH, &hwr, false);
|
|
|
|
|
|
ws.start(true);
|