$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: lists.drrngrvy_at_[hidden]
Date: 2008-03-21 14:17:06
Author: drrngrvy
Date: 2008-03-21 14:17:06 EDT (Fri, 21 Mar 2008)
New Revision: 43760
URL: http://svn.boost.org/trac/boost/changeset/43760
Log:
Adding basic example testing multipart forms.
Text files modified: 
   sandbox/SOC/2007/cgi/branches/acceptor_work/libs/cgi/example/acgi/echo/main.cpp |    90 +++++++++++++++++++++++++++++++-------- 
   1 files changed, 70 insertions(+), 20 deletions(-)
Modified: sandbox/SOC/2007/cgi/branches/acceptor_work/libs/cgi/example/acgi/echo/main.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/branches/acceptor_work/libs/cgi/example/acgi/echo/main.cpp	(original)
+++ sandbox/SOC/2007/cgi/branches/acceptor_work/libs/cgi/example/acgi/echo/main.cpp	2008-03-21 14:17:06 EDT (Fri, 21 Mar 2008)
@@ -14,6 +14,8 @@
 //
 
 #include <boost/cgi/acgi.hpp>
+#include <fstream>
+//#include <google/template.h>
 
 using namespace std;
 using namespace boost::acgi;
@@ -33,24 +35,72 @@
 
 int main()
 {
-  service s;
-  request req(s);
-
-  req.load(true); // The 'true' means parse STDIN data too.
-
-  response resp;
-
-  show_map_contents(req.env(), resp, "Environment Variables");
-  show_map_contents(req.GET(), resp, "GET Variables");
-  show_map_contents(req.POST(), resp, "POST Variables");
-  show_map_contents(req.cookie(), resp, "Cookie Variables");
-
-  // Note that this (and any other) HTTP header can go either before or after
-  // the response contents.
-  resp<< content_type("text/html");
-
-  // Send the response to the client associated with the request.
-  resp.send(req.client());
-
-  return 0;
+  try{
+    //std::ofstream of("c:/cc/log/cgi.error");
+    //if (!of)
+    //  throw std::runtime_error("Couldn't open file for writing");
+    //std::cerr.rdbuf() = of.rdbuf();
+    service s;
+    request req(s);
+
+    try {
+
+      boost::system::error_code ec;
+      req.load(ec, true);
+
+      if (ec)
+      {
+        response resp;
+        resp
+        << content_type("text/plain")
+        << "Error " << ec.value() << ": " << ec.message() << "<p />"
+           "--Original message follows--"
+           "<p />";
+        resp.send(req.client());
+      }
+
+      response resp;
+      resp<< content_type("text/html")
+          << "<form method=POST enctype='multipart/form-data'>"
+              "<input type=text name=name value='" << req.POST("name") << "' />"
+              "<br />"
+              "<input type=text name=hello value='" << req.POST("hello") << "' />"
+              "<br />"
+              "<input type=file name=user_file />"
+              "<input type=hidden name=cmd value=multipart_test />"
+              "<br />"
+              "<input type=submit value=submit />"
+             "</form><p />"
+             "boundary marker = " << req.boundary_marker() << "<p />";
+
+      show_map_contents(req.GET(), resp, "GET Variables");
+      show_map_contents(req.POST(), resp, "POST Variables");
+      show_map_contents(req.cookie(), resp, "Cookie Variables");
+      show_map_contents(req.env(), resp, "Environment Variables");
+
+      //resp<< content_type("text/html");
+      resp.send(req.client());
+
+    }catch(boost::system::error_code& ec){
+      response resp;
+      resp<< content_type("text/plain") << "Error " << ec.value() << ": "
+          << ec.message();
+    }catch(std::exception& e){
+      response resp;
+      resp<< content_type("text/plain") << "Error: " << e.what();
+      return_(resp, req, 2);
+    }
+
+  }catch(std::exception* e){
+    std::cout
+    << content_type("text/plain").content
+    << "Exception: " << e->what();
+    //resp.send(req.client());
+    return 3;
+  }catch(...){
+    std::cout<< content_type("text/plain").content
+             << "Unknown error.";
+    return 4;
+  }
+ return 0;
 }