{"id":5673,"date":"2026-05-09T21:07:33","date_gmt":"2026-05-09T12:07:33","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5673"},"modified":"2026-05-09T21:18:24","modified_gmt":"2026-05-09T12:18:24","slug":"webserver-miniwebserver-8","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/05\/09\/webserver-miniwebserver-8\/","title":{"rendered":"[Webserver]miniWebserver-(8)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc8fc\uc694\ubcc0\uacbd\uc0ac\ud56d\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>The major changes are as follows.<\/p>\n\n\n\n<p>\u2714\ufe0f GET,POST,PUT,DELETE,FETCH \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can use GET, POST, PUT, DELETE, and FETCH methods.<\/p>\n\n\n\n<p>\u2714\ufe0f \uc8fc\uc694 \ubcc0\uacbd \uc0ac\ud56d\uc740 \uae30\uc874\uc758 \ud568\uc218\uc5d0\uc11c method \ubd80\ubd84\uc774 \ucd94\uac00\ub418\uc5c8\uc2b5\ub2c8\ub2e4.<br>The main change is that a method part has been added to the existing function.<\/p>\n\n\n\n<p>\u2714\ufe0f \ud14c\uc2a4\ud2b8\ub294 GET,POST\ub9cc \ud14c\uc2a4\ud2b8 \ud588\uc2b5\ub2c8\ub2e4.<br>Only GET and POST were tested.<\/p>\n\n\n\n<p>\u2714\ufe0f \uba54\uc18c\ub4dc \ucd94\ucd9c\ud558\ub294 \ubd80\ubd84\uc740 \uc544\ub798 \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>The part for extracting the method is the section below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        std::istringstream req_stream(req);\n        std::string method, path, http_version;\n        req_stream &gt;&gt; method &gt;&gt; path &gt;&gt; http_version;<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ub2e4\ub978 \ubcc0\uacbd\uc0ac\ud56d\uc740 \uae43\ud5c8\ube0c\uc758 \ucf54\ub4dc\uc5d0\uc11c Router.h\uc640 Router.cpp\ud30c\uc77c\uc744 \ucc38\uc870\ud558\uc138\uc694<br>For other changes, please refer to the Router.h and Router.cpp files in the code on GitHub.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/gideonslife01\/flm-Cpp\">https:\/\/github.com\/gideonslife01\/flm-Cpp<\/a><\/p>\n\n\n\n<p>\u2714\ufe0f \u2757\ufe0f \ud45c\uc2dc\ub41c \ubd80\ubd84\uc774 \ubcc0\uacbd\uc0ac\ud56d\uc785\ub2c8\ub2e4.<br>The parts marked with \u2757\ufe0f are the changes.<\/p>\n\n\n\n<p>\u2714\ufe0f main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/ -- \ub77c\uc6b0\ud2b8 \uc124\uc815 \ubcc0\uacbd \/ Change route settings -- \/\/\u2757\ufe0f\n    Router server1_router(\"..\/public1\");\n    server1_router.add_route(\"GET\",\"\/test1\", \"test1.html\");\n    server1_router.add_route(\"POST\",\"\/test2\", \"test2.html\");\n\n    Router server2_router(\"..\/public2\");\n    server2_router.add_route(\"GET\",\"\/test1\", \"test1.html\");\n    server2_router.add_route(\"POST\",\"\/test2\", \"test2.html\");\n\n    \/\/ --- \uc11c\ubc84 1 \uc124\uc815 (5080 \ud3ec\ud2b8) --- \/\/ \u2757\ufe0f\n    \/\/ --- Server 1 Configuration (Port 5080) --- \/\/\n    Server server1(\"127.0.0.1\", 5080);\n    server1.set_handler(&#91;&amp;](const std::string&amp; req) {\n        \/\/ method \uac80\uc0ac\n        std::istringstream req_stream(req);\n        std::string method, path, http_version;\n        req_stream &gt;&gt; method &gt;&gt; path &gt;&gt; http_version;\n\n        std::pair&lt;std::string, std::string&gt; result;\n\n        if (method == \"GET\" || method == \"POST\" || method == \"PUT\" || method == \"DELETE\" || method == \"FETCH\") {\n            result = server1_router.router(method, path);\n        }\n        else {\n            return std::string(\n                \"HTTP\/1.1 405 Method Not Allowed\\r\\n\"\n                \"Allow: GET, POST, PUT, DELETE, FETCH\\r\\n\"\n                \"Connection: close\\r\\n\\r\\n\"\n                \"Method Not Allowed\"\n            );\n        }\n\n        \/\/ \ub77c\uc6b0\ud130\ub85c\ubd80\ud130 \ub9c8\uc784 \ud0c0\uc785\uacfc \ubcf8\ubb38\uc744 \ubc1b\uc74c\n        \/\/ Receive MIME type and body from router\n        \/\/auto &#91;mime, body] = server1_router.router(req); \/\/ \uc774\uc804\ubc29\uc2dd\u2757\ufe0f\n        const auto&amp; &#91;mime, body] = result;\n\n        \/\/ HTTP \uc751\ub2f5 \ud5e4\ub354 \uc0dd\uc131\n        \/\/ Generate HTTP response headers\n        std::string response = \"HTTP\/1.1 200 OK\\r\\n\";\n        response += \"Content-Type: \" + mime + \"\\r\\n\";\n        response += \"Content-Length: \" + std::to_string(body.size()) + \"\\r\\n\";\n        response += \"Connection: close\\r\\n\";\n        response += \"\\r\\n\"; \/\/ \ud5e4\ub354\uc640 \ubcf8\ubb38 \uad6c\ubd84\uc790 \/ Header and body separator\n\n        \/\/ \ubcf8\ubb38 \ucd94\uac00 \/ Add body\n        response += body;\n\n        \/\/ \ucd5c\uc885 \uc751\ub2f5 \ubc18\ud658 \/ Return final response\n        return response;\n    });<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ube4c\ub4dc \/ Build<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd build\ncmake ..\nmake<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MacBookAir build % .\/main\n--- Starting Server Application ---\nServer listening on port 5080...\nServer listening on port 6080...\nCMD&gt; <\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ube0c\ub77c\uc6b0\uc800 \uc811\uc18d \/ Access Browser<\/p>\n\n\n\n<p>\u2714\ufe0f \ube0c\ub77c\uc6b0\uc800\uc5d0\ub294 5080,6080 \ud3ec\ud2b8\ub85c \uc811\uc18d\ud569\ub2c8\ub2e4.<br>Connect to ports 5080 and 6080 in the browser.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:5080\nhttp:\/\/localhost:6080<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f POST\ub294 \uc544\ub798\uc758 test1.htm\uc5d0\uc11c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can test the POST in test1.htm below.<\/p>\n\n\n\n<p>&#8212; \ub9cc\uc57d\uc5d0 \ud3fc\uc73c\ub85c \ub370\uc774\ud130\ub97c \uc804\uc1a1\ud558\uc9c0\uc54a\uace0 \ub9c1\ud06c\ub85c test2.html\uc5d0 \uc811\uadfc\ud558\uba74 404\uc624\ub958(404 Not Found)\uac00 \ubc1c\uc0dd\ud569\ub2c8\ub2e4.<br>If you access test2.html via a link without submitting data through the form, a 404 error (404 Not Found) occurs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:5080\/test1.html\nhttp:\/\/localhost:6080\/test1.html<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc8fc\uc694\ubcc0\uacbd\uc0ac\ud56d\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.The major changes are as follows. \u2714\ufe0f GET,POST,PUT,DELETE,FETCH \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.You can use GET, POST, PUT, DELETE, and FETCH methods. \u2714\ufe0f \uc8fc\uc694 \ubcc0\uacbd \uc0ac\ud56d\uc740 \uae30\uc874\uc758 \ud568\uc218\uc5d0\uc11c method \ubd80\ubd84\uc774 \ucd94\uac00\ub418\uc5c8\uc2b5\ub2c8\ub2e4.The main change is that a method part has been added to the existing function. \u2714\ufe0f \ud14c\uc2a4\ud2b8\ub294 GET,POST\ub9cc \ud14c\uc2a4\ud2b8 \ud588\uc2b5\ub2c8\ub2e4.Only GET and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5673","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5673"}],"version-history":[{"count":4,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5673\/revisions"}],"predecessor-version":[{"id":5678,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5673\/revisions\/5678"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}