{"id":48,"date":"2014-04-19T06:14:50","date_gmt":"2014-04-19T05:14:50","guid":{"rendered":"http:\/\/code.sualdea.com\/?p=48"},"modified":"2015-04-01T22:25:06","modified_gmt":"2015-04-01T21:25:06","slug":"bashttp-mini-web-server","status":"publish","type":"post","link":"https:\/\/code.sualdea.com\/?p=48","title":{"rendered":"bashttp mini web server"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h1 class=\"western\">What is it<\/h1>\n<p>It&#8217;s a micro web server that features php and web service extension<\/p>\n<h1>Build<\/h1>\n<p>Dependencies: <a href=\"http:\/\/pocoproject.org\/\">Poco c++ libraries<\/a><\/p>\n<p>For linux:<\/p>\n<p>[cc lang=&#8221;bash&#8221;]<\/p>\n<p>~\/bashttp $ rm -rf build\/<br \/>\n~\/bashttp $ mkdir -p build\/debug<br \/>\n~\/bashttp $ cd build\/debug\/<br \/>\n~\/bashttp $ cmake ..\/.. -DCMAKE_BUILD_TYPE=Debug<br \/>\n~\/bashttp $ make<\/p>\n<p>[\/cc]<\/p>\n<p>For windows use cmake-gui from <a href=\"http:\/\/www.cmake.org\/\">http:\/\/www.cmake.org\/<\/a>.<\/p>\n<h1 class=\"western\">How to run<\/h1>\n<p>To run it<\/p>\n<p>[cc lang=\u201dbash\u201d]<br \/>\n~\/bashttp $ bashttp 8888 doc_root<br \/>\nbashttp listening on 127.0.0.1:8888<br \/>\n[\/cc]<\/p>\n<p>Where 8888 is the port and &#8216;doc_root&#8217; is the document root directory<\/p>\n<p>To stop it simply press ctr+c<\/p>\n<h1 class=\"western\">Configuration and test files<\/h1>\n<p><a href=\"http:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/miniwebserver-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-56\" src=\"http:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/miniwebserver-files-300x124.png\" alt=\"miniwebserver-files\" width=\"300\" height=\"124\" srcset=\"https:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/miniwebserver-files-300x124.png 300w, https:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/miniwebserver-files.png 366w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>doc_root: document root directory<\/p>\n<p>doc_root\/index.html: html test page<\/p>\n<p>doc_root\/index.php: php test page<\/p>\n<p>mime.conf: mime configuration. Must be in execution directory.<\/p>\n<p>\/etc\/alternatives\/php-cgi: php binary for linux<\/p>\n<p>php.cgi.exe: php binary for windows. Must be in execution directory.<\/p>\n<h1 class=\"western\">\ud83d\ude08 Execute shell from browser \ud83d\ude08<\/h1>\n<p><a href=\"http:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/Screenshot-from-2014-04-19-070856.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-59 size-full\" src=\"http:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/Screenshot-from-2014-04-19-070856.png\" alt=\"Screenshot from 2014-04-19 07:08:56\" width=\"699\" height=\"407\" srcset=\"https:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/Screenshot-from-2014-04-19-070856.png 699w, https:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/Screenshot-from-2014-04-19-070856-300x174.png 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/a><\/p>\n<h1 class=\"western\">Write a new web service<\/h1>\n<p>Example of service that would be called as &#8216;http:\/\/server\/newservice&#8217;:<\/p>\n<p><code><br \/>\nclass NewService : public MiniWebService<br \/>\n{<br \/>\npublic:<br \/>\n\tvirtual void exec(const Poco::Net::HTTPServerRequest& request,<br \/>\n\t\t\t\t\t\tstd::map<std::string, std::string> &query,<br \/>\n\t\t\t\t\t\tPoco::Net::HTTPServerResponse& response,<br \/>\n\t\t\t\t\t\tPoco::Net::StreamSocket& sock,<br \/>\n\t\t\t\t\t\tPoco::Net::HTTPServerSession& session)<br \/>\n\t{<br \/>\n\t\tstd::ostream& ostr = response.send();<br \/>\n\t\tostr << \"it works.\";\n\t\tostr.flush();\n\t}\n\n\tstatic std::string name() { return \"newservice\"; }\n};\n<\/code><\/p>\n<p>Where:<\/p>\n<ul>\n<li>name() method returns the web service identifier as seen in url<\/li>\n<\/ul>\n<ul>\n<li>exec(...) implements the web service.<\/li>\n<\/ul>\n<p>Add it to server before start it<\/p>\n<p>[cc lang=\u201dcpp\u201d]<\/p>\n<p>std::shared_ptr svc(new NewService());<br \/>\nserver.addService(NewService::name(), svc);<\/p>\n<p>[\/cc]<\/p>\n<h1>Download<\/h1>\n<p><a href=\"http:\/\/code.sualdea.com\/wp-content\/uploads\/2014\/04\/bashttp.zip\">download here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; What is it It&#8217;s a micro web server that features php and web service extension Build Dependencies: Poco c++ libraries For linux: [cc lang=&#8221;bash&#8221;] ~\/bashttp $ rm -rf build\/ ~\/bashttp $ mkdir -p build\/debug ~\/bashttp $ cd build\/debug\/ ~\/bashttp $ cmake ..\/.. -DCMAKE_BUILD_TYPE=Debug ~\/bashttp $ make [\/cc] For windows use cmake-gui from http:\/\/www.cmake.org\/. How &hellip; <a href=\"https:\/\/code.sualdea.com\/?p=48\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">bashttp mini web server<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,10,6,5],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-http","tag-linux","tag-windows"],"_links":{"self":[{"href":"https:\/\/code.sualdea.com\/index.php?rest_route=\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.sualdea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.sualdea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.sualdea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code.sualdea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":25,"href":"https:\/\/code.sualdea.com\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":143,"href":"https:\/\/code.sualdea.com\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions\/143"}],"wp:attachment":[{"href":"https:\/\/code.sualdea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.sualdea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.sualdea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}