Ver Fonte

Updated libhttpserver to the latest version (0.17.5). (#4389)

* Updated libhttpserver to the latest version (0.17.5).

Version 0.17.5 focuses primarly in performance improvements.

* Use C++ 11 as default c++ syntax version
Sebastiano Merlino há 6 anos atrás
pai
commit
8713da566f

+ 16 - 9
frameworks/C++/libhttpserver/benchmark.cpp

@@ -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);

+ 2 - 2
frameworks/C++/libhttpserver/libhttpserver.dockerfile

@@ -7,7 +7,7 @@ ENV LHT_HOME /libhttpserver
 WORKDIR ${LHT_HOME}
 
 ENV LIBMICROHTTPD_VERSION 0.9.59
-ENV LIBHTTPSERVER_VERSION 0.16.0
+ENV LIBHTTPSERVER_VERSION 0.17.5
 
 RUN curl https://s3.amazonaws.com/libhttpserver/libmicrohttpd_releases/libmicrohttpd-${LIBMICROHTTPD_VERSION}.tar.gz -o libmicrohttpd-${LIBMICROHTTPD_VERSION}.tar.gz
 RUN tar -xvzf libmicrohttpd-${LIBMICROHTTPD_VERSION}.tar.gz
@@ -20,5 +20,5 @@ COPY benchmark.cpp benchmark.cpp
 
 ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
 
-RUN g++ -O3 -o benchmark benchmark.cpp -lhttpserver -L/usr/local/lib
+RUN g++ -O3 -std=c++11 -o benchmark benchmark.cpp -lhttpserver -L/usr/local/lib
 CMD ./benchmark 8080 $(nproc)