From 1c942c34b73cf10f7da38f37ef95a10e963b0941 Mon Sep 17 00:00:00 2001 From: xx Date: Wed, 10 Nov 2021 21:17:20 +0800 Subject: [PATCH] update --- build.sh | 8 ++++++++ examples/hello_world.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 build.sh diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..59b0b646 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +# cd ~/libhttpserver/ +# ./bootstrap +# mkdir ~/build/libhttpserver +cd ~/build/libhttpserver +#~/libhttpserver/configure +make +sudo supervisorctl restart hello-word +#make hello-world diff --git a/examples/hello_world.cpp b/examples/hello_world.cpp index 880c811a..cf3a877e 100755 --- a/examples/hello_world.cpp +++ b/examples/hello_world.cpp @@ -29,8 +29,13 @@ class hello_world_resource : public httpserver::http_resource { std::string data; }; +const std::shared_ptr MakeResponse(std::string const & value){ + auto s = std::shared_ptr(new httpserver::string_response(value, 200, "text/html; charset=UTF-8")); + return s; +} // Using the render method you are able to catch each type of request you receive -const std::shared_ptr hello_world_resource::render(const httpserver::http_request& req) { +const std::shared_ptr +hello_world_resource::render(const httpserver::http_request& req) { // It is possible to store data inside the resource object that can be altered through the requests std::cout << "Data was: " << data << std::endl; std::string datapar = req.get_arg("data"); @@ -38,7 +43,7 @@ const std::shared_ptr hello_world_resource::render(co std::cout << "Now data is:" << data << std::endl; // It is possible to send a response initializing an http_string_response that reads the content to send in response from a string. - return std::shared_ptr(new httpserver::string_response("Hello World!!!", 200)); + return MakeResponse("Hello 唐娟!!!"); } int main() {