[mapguide-commits] r9712 - in trunk/MgDev: . Oem/cpp-httplib Web/src/DevHttpServer

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Aug 14 03:38:58 PDT 2020


Author: jng
Date: 2020-08-14 03:38:57 -0700 (Fri, 14 Aug 2020)
New Revision: 9712

Added:
   trunk/MgDev/Oem/cpp-httplib/CHANGES.txt
Modified:
   trunk/MgDev/Oem/cpp-httplib/httplib.h
   trunk/MgDev/Web/src/DevHttpServer/main.cpp
   trunk/MgDev/build.bat
Log:
#2811: Make wwwroot configurable in MgDevHttpServer and add support for ignoring routes as static file requests (needed so that requests for mapagent.fcgi do not try to get the physical file). Also update build.bat to copy MgDevHttpServer to the install staging area

Added: trunk/MgDev/Oem/cpp-httplib/CHANGES.txt
===================================================================
--- trunk/MgDev/Oem/cpp-httplib/CHANGES.txt	                        (rev 0)
+++ trunk/MgDev/Oem/cpp-httplib/CHANGES.txt	2020-08-14 10:38:57 UTC (rev 9712)
@@ -0,0 +1,4 @@
+14 Aug 2020
+===========
+
+Added ability to register request paths (add_static_file_ignore) to not treat as static file requests. Needed so that requests for mapagent.fcgi do not try to get the physical file. 
\ No newline at end of file

Modified: trunk/MgDev/Oem/cpp-httplib/httplib.h
===================================================================
--- trunk/MgDev/Oem/cpp-httplib/httplib.h	2020-08-14 08:21:30 UTC (rev 9711)
+++ trunk/MgDev/Oem/cpp-httplib/httplib.h	2020-08-14 10:38:57 UTC (rev 9712)
@@ -203,6 +203,7 @@
 #include <random>
 #include <regex>
 #include <string>
+#include <set>
 #include <sys/stat.h>
 #include <thread>
 
@@ -599,6 +600,9 @@
   bool is_running() const;
   void stop();
 
+  // Add a request path that should be ignored
+  void add_static_file_ignore(const char* requestPath);
+
   std::function<TaskQueue *(void)> new_task_queue;
 
 protected:
@@ -672,6 +676,8 @@
 
   bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY;
   SocketOptions socket_options_ = default_socket_options;
+
+  std::set<std::string> ignore_static_file_reqs_;
 };
 
 class Client {
@@ -4210,9 +4216,11 @@
 inline bool Server::routing(Request &req, Response &res, Stream &strm) {
   // File handler
   bool is_head_request = req.method == "HEAD";
-  if ((req.method == "GET" || is_head_request) &&
-      handle_file_request(req, res, is_head_request)) {
-    return true;
+  if (ignore_static_file_reqs_.find(req.path) == ignore_static_file_reqs_.end()) {
+      if ((req.method == "GET" || is_head_request) &&
+          handle_file_request(req, res, is_head_request)) {
+          return true;
+      }
   }
 
   if (detail::expect_content(req)) {
@@ -4406,6 +4414,11 @@
   return ret;
 }
 
+inline void Server::add_static_file_ignore(const char* requestPath)
+{
+  ignore_static_file_reqs_.insert(std::string(requestPath));
+}
+
 // HTTP client implementation
 inline Client::Client(const std::string &host)
     : Client(host, 80, std::string(), std::string()) {}

Modified: trunk/MgDev/Web/src/DevHttpServer/main.cpp
===================================================================
--- trunk/MgDev/Web/src/DevHttpServer/main.cpp	2020-08-14 08:21:30 UTC (rev 9711)
+++ trunk/MgDev/Web/src/DevHttpServer/main.cpp	2020-08-14 10:38:57 UTC (rev 9712)
@@ -477,6 +477,7 @@
 #endif
 #endif
 
+    std::string wwwroot;
     STRING wcPath = L"webconfig.ini";
     try 
     {
@@ -486,13 +487,17 @@
         TCLAP::ValueArg<std::string> argMentorPath("m", "mentor-dictionary-path", "The path to the CS-MAP dictionary data files. Not required if this path is set in webconfig.ini", false, "", "path");
         TCLAP::ValueArg<int> argPort("p", "port", "The port this server will listen on", false, 8000, "integer");
         TCLAP::ValueArg<std::string> argWebConfigPath("w", "webconfig-path", "The path to webconfig.ini", false, "webconfig.ini", "path");
+        TCLAP::ValueArg<std::string> argWebRootPath("r", "wwwroot", "The path to the www root", false, "./wwwroot", "path");
 
         cmd.add(argMentorPath);
         cmd.add(argPort);
         cmd.add(argWebConfigPath);
+        cmd.add(argWebRootPath);
 
         cmd.parse(argc, argv);
 
+        wwwroot = argWebRootPath.getValue();
+
         auto mentorPath = argMentorPath.getValue();
         if (!mentorPath.empty())
         {
@@ -526,6 +531,11 @@
     {
         MG_TRY()
 
+        if (!MgFileUtil::PathnameExists(wcPath))
+        {
+            printf("ERROR: web config path (%S) not found. If this file is in a custom location, specify it with the --webconfig-path flag\n", wcPath.c_str());
+            return -1;
+        }
         MgInitializeWebTier(wcPath);
         bInit = true;
 
@@ -542,8 +552,12 @@
     {
         g_server.reset(new httplib::Server());
 
-        g_server->set_mount_point("/mapguide", "./wwwroot");
+        g_server->set_mount_point("/mapguide", wwwroot.c_str());
+        printf("Using www root: %s\n", wwwroot.c_str());
 
+        // In the event this file physically exists on the wwwroot, ignore it
+        g_server->add_static_file_ignore("/mapguide/mapagent/mapagent.fcgi");
+
         g_server->Post("/mapguide/mapagent/mapagent.fcgi", MapAgentHandlerWithContentReader);
         g_server->Post("/mapguide/mapagent/mapagent.fcgi", MapAgentHandlerWithoutContentReader);
         g_server->Get("/mapguide/mapagent/mapagent.fcgi", MapAgentHandlerWithoutContentReader);

Modified: trunk/MgDev/build.bat
===================================================================
--- trunk/MgDev/build.bat	2020-08-14 08:21:30 UTC (rev 9711)
+++ trunk/MgDev/build.bat	2020-08-14 10:38:57 UTC (rev 9712)
@@ -340,6 +340,14 @@
 if not "%errorlevel%"=="0" goto error
 echo [install]: Web Tier - fusion templates
 %XCOPY% "%MG_OEM%\fusionMG" "%MG_OUTPUT_WEB%\www\fusion" /EXCLUDE:svn_excludes.txt+%CONFIGURATION%_excludes.txt
+echo [install]: Web Tier - MgDevHttpServer
+if not exist "%MG_OUTPUT_WEB%\DevHttpServer" mkdir "%MG_OUTPUT_WEB%\DevHttpServer"
+copy /Y "%MG_WEB_BIN%\%TYPEBUILD%\Mg*.dll" "%MG_OUTPUT_WEB%\DevHttpServer"
+copy /Y "%MG_WEB_BIN%\%TYPEBUILD%\ACE.dll" "%MG_OUTPUT_WEB%\DevHttpServer"
+copy /Y "%MG_WEB_BIN%\%TYPEBUILD%\GEOS.dll" "%MG_OUTPUT_WEB%\DevHttpServer"
+copy /Y "%MG_WEB_BIN%\%TYPEBUILD%\lib_json.dll" "%MG_OUTPUT_WEB%\DevHttpServer"
+copy /Y "%MG_WEB_BIN%\%TYPEBUILD%\xerces-c_3_1mg.dll" "%MG_OUTPUT_WEB%\DevHttpServer"
+copy /Y "%MG_WEB_BIN%\%TYPEBUILD%\DevHttpServer\*.exe" "%MG_OUTPUT_WEB%\DevHttpServer"
 echo [install]: Web Tier - Apache module
 if not exist "%MG_OUTPUT_WEB%\Apache24\modules" mkdir "%MG_OUTPUT_WEB%\Apache24\modules"
 %XCOPY% /F "%MG_BUILD_MAPAGENT%" "%MG_OUTPUT_WEB%\Apache24\modules"



More information about the mapguide-commits mailing list