Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2007-08-22 21:25:52


Author: drrngrvy
Date: 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
New Revision: 38860
URL: http://svn.boost.org/trac/boost/changeset/38860

Log:
Changing reply -> response and adding operator<< overloads to take both headers and cookies, which are also included. Also various fixes/modifications/refactorings.
Added:
   sandbox/SOC/2007/cgi/boost/cgi/cookie.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/boost/cgi/header.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/boost/cgi/response.hpp (contents, props changed)
Removed:
   sandbox/SOC/2007/cgi/boost/cgi/reply.hpp
Text files modified:
   sandbox/SOC/2007/cgi/boost/cgi/acgi.hpp | 12 ++++
   sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp | 4
   sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp | 100 ++++++++++++++++++++++++----------------
   sandbox/SOC/2007/cgi/boost/cgi/cgi.hpp | 14 ++++-
   sandbox/SOC/2007/cgi/boost/cgi/cgi/service.hpp | 2
   sandbox/SOC/2007/cgi/boost/cgi/request_ostream.hpp | 38 ++++++++++++++-
   sandbox/SOC/2007/cgi/boost/cgi/status_type.hpp | 2
   7 files changed, 119 insertions(+), 53 deletions(-)

Modified: sandbox/SOC/2007/cgi/boost/cgi/acgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/acgi.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/acgi.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -18,12 +18,20 @@
 #include "gateway_service/acgi_gateway_service.hpp"
 
 // Include headers common to all protocols
-#include "detail/common_headers.hpp"
+#include "boost/cgi/detail/common_headers.hpp"
 
 namespace cgi {
 #ifndef CGI_NO_IMPLICIT_TYPEDEFS
- typedef acgi_request request;
+ //typedef acgi_request request;
 #endif
+ namespace acgi {
+
+ typedef acgi_request request;
+ typedef acgi_service service;
+ //typedef acgi_acceptor acceptor;
+ using namespace cgi;
+
+ } // namespace acgi
 } // namespace cgi
 
 #endif // CGI_ACGI_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/basic_protocol_service.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -97,8 +97,8 @@
     void reset()
     {
       request_queue_.clear();
- std::for_each(request_set_.begin(), request_set_.end()
- , boost::bind(&request_type::abort, boost::ref(*_1)));
+ //std::for_each(request_set_.begin(), request_set_.end()
+ // , boost::bind(&request_type::abort, boost::arg<1>()));
       request_set_.clear();
       ios_provider_.reset();
     }

Modified: sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/basic_request.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -79,6 +79,7 @@
     typedef typename service_type::protocol_type protocol_type;
     typedef ProtocolService protocol_service_type;
     typedef boost::shared_ptr<type> pointer;
+ typedef typename RequestService::implementation_type implementation_type;
 
 
     // Throws
@@ -207,6 +208,12 @@
       return this->service.close(this->impl, http::internal_server_error);
     }
 
+ /// Abort a request
+ void abort()
+ {
+ this->service.set_status(this->impl, aborted);
+ }
+
     /// Set the output for the request
     /**
      * Not Implemented Yet ******************
@@ -276,7 +283,7 @@
     }
 
     /// Get a `cgi::map&` corresponding to all of the GET variables
- cgi::map& meta_get()
+ cgi::map& get_()
     {
       return this->service.meta_get(this->impl);
     }
@@ -287,7 +294,7 @@
      * fail with `cgi::error::request_aborted` if the request has been aborted
      * by the client.
      */
- std::string meta_get(const std::string& name)
+ std::string get_(const std::string& name)
     {
       boost::system::error_code ec;
       std::string ret = this->service.meta_get(this->impl, name, ec);
@@ -301,13 +308,13 @@
      * fail with `ec == cgi::error::request_aborted` if the request has been
      * aborted by the client.
      */
- std::string meta_get(const std::string& name, boost::system::error_code& ec)
+ std::string get_(const std::string& name, boost::system::error_code& ec)
     {
       return this->service.meta_get(this->impl, name, ec);
     }
 
     /// Get a `cgi::map&` corresponding to all of the POST variables
- cgi::map& meta_post()
+ cgi::map& post_()
     {
       return this->service.meta_post(this->impl);
     }
@@ -322,7 +329,7 @@
      * fail with `cgi::error::request_aborted` if the request has been aborted
      * by the client.
      */
- std::string meta_post(const std::string& name, bool greedy = true)
+ std::string post_(const std::string& name, bool greedy = true)
     {
       boost::system::error_code ec;
       std::string ret = this->service.meta_post(this->impl, name, ec, greedy);
@@ -335,14 +342,14 @@
      * fail with `ec == cgi::error::request_aborted` if the request has been
      * aborted by the client.
      */
- std::string meta_post(const std::string& name, boost::system::error_code& ec
+ std::string post_(const std::string& name, boost::system::error_code& ec
                           , bool greedy = true)
     {
       return this->service.meta_post(this->impl, name, ec, greedy);
     }
 
     /// Get a `cgi::map&` corresponding to all of the form variables
- cgi::map& meta_form()
+ cgi::map& form_()
     {
       return this->service.meta_form(this->impl);
     }
@@ -356,10 +363,10 @@
      * fail with `cgi::error::request_aborted` if the request has been aborted
      * by the client.
      */
- std::string meta_form(const std::string& name, bool greedy = true)
+ std::string form_(const std::string& name, bool greedy = true)
     {
       boost::system::error_code ec;
- std::string ret = meta_form(name, ec, greedy);
+ std::string ret = form_(name, ec, greedy);
       detail::throw_error(ec);
       return ret;
     }
@@ -369,7 +376,7 @@
      * fail with `ec == cgi::error::request_aborted` if the request has been
      * aborted by the client.
      */
- std::string meta_form(const std::string& name, boost::system::error_code& ec
+ std::string form_(const std::string& name, boost::system::error_code& ec
                          , bool greedy = true)
     {
       std::string rm(request_method());
@@ -383,7 +390,7 @@
     }
 
     /// Get a `cgi::map&` corresponding to all of the HTTP_COOKIE variables
- cgi::map& meta_cookie()
+ cgi::map& cookie_()
     {
       return this->service.meta_cookie(this->impl);
     }
@@ -394,7 +401,7 @@
      * fail with `cgi::error::request_aborted` if the request has been aborted
      * by the client.
      */
- std::string cookie(const std::string& name)
+ std::string cookie_(const std::string& name)
     {
       boost::system::error_code ec;
       std::string ret = this->service.cookie(this->impl, name, ec);
@@ -408,18 +415,24 @@
      * fail with `ec == cgi::error::request_aborted` if the request has been
      * aborted by the client.
      */
- std::string cookie(const std::string& name, boost::system::error_code& ec)
+ std::string cookie_(const std::string& name, boost::system::error_code& ec)
     {
       return this->service.cookie(this->impl, name, ec);
     }
 
+ /// Get a `cgi::map&` corresponding to all of the environment variables
+ cgi::map& env_()
+ {
+ return this->service.meta_env(this->impl);
+ }
+
     /// Find the environment meta-variable matching name
     /**
      * @throws `boost::system::system_error` if an error occurred. This may
      * fail with `cgi::error::request_aborted` if the request has been aborted
      * by the client.
      */
- std::string meta_env(const std::string& name)
+ std::string env_(const std::string& name)
     {
       boost::system::error_code ec;
       std::string ret = this->service.meta_env(this->impl, name, ec);
@@ -433,7 +446,7 @@
      * fail with `ec == cgi::error::request_aborted` if the request has been
      * aborted by the client.
      */
- std::string meta_env(const std::string& name, boost::system::error_code& ec)
+ std::string env_(const std::string& name, boost::system::error_code& ec)
     {
       return this->service.meta_env(this->impl, name, ec);
     }
@@ -452,93 +465,93 @@
      * provide a meta_var_all() function which is greedy; the
      * ugly/long name there to discourage use.
      */
- std::string meta_var(const std::string& name, bool greedy = false)
+ std::string var_(const std::string& name, bool greedy = false)
     {
       boost::system::error_code ec;
- std::string ret = meta_var(name, ec, greedy);
+ std::string ret = var_(name, ec, greedy);
       return this->service.meta_var(this->impl, name, greedy);
- std::string request_method( meta_env("REQUEST_METHOD") );
+ std::string request_method( env_("REQUEST_METHOD") );
 
       std::string tmp;
 
       // If it's not a POST request search meta_get first (to save time)
       if (request_method.empty() || request_method == "GET")
       {
- tmp = meta_get(name);
+ tmp = get_(name);
         if (!tmp.empty())
           return tmp;
       }
 
- tmp = cookie(name);
+ tmp = cookie_(name);
       if (!tmp.empty())
               return tmp;
 
- tmp = meta_env(name);
+ tmp = env_(name);
       if (!tmp.empty())
               return tmp;
 
       if (!request_method.empty() && request_method == "POST")
       {
- tmp = meta_post(name);
+ tmp = post_(name);
         if (!tmp.empty())
           return tmp;
       }
 
- tmp = meta_get(name);
+ tmp = get_(name);
       return tmp.empty() ? "" : tmp;
     }
 
     // Some helper functions for the basic CGI 1.1 meta-variables
     std::string auth_type()
- { return meta_env("AUTH_TYPE"); }
+ { return env_("AUTH_TYPE"); }
 
     std::string content_length()
- { return meta_env("CONTENT_LENGTH"); }
+ { return env_("CONTENT_LENGTH"); }
 
     std::string content_type()
- { return meta_env("CONTENT_TYPE"); }
+ { return env_("CONTENT_TYPE"); }
 
     std::string gateway_interface()
- { return meta_env("GATEWAY_INTERFACE"); }
+ { return env_("GATEWAY_INTERFACE"); }
 
     std::string path_info()
- { return meta_env("PATH_INFO"); }
+ { return env_("PATH_INFO"); }
 
     std::string path_translated()
- { return meta_env("PATH_TRANSLATED"); }
+ { return env_("PATH_TRANSLATED"); }
 
     std::string query_string()
- { return meta_env("QUERY_STRING"); }
+ { return env_("QUERY_STRING"); }
 
     std::string remote_addr()
- { return meta_env("REMOTE_ADDR"); }
+ { return env_("REMOTE_ADDR"); }
 
     std::string remote_host()
- { return meta_env("REMOTE_HOST"); }
+ { return env_("REMOTE_HOST"); }
 
     std::string remote_ident()
- { return meta_env("REMOTE_IDENT"); }
+ { return env_("REMOTE_IDENT"); }
 
     std::string remote_user()
- { return meta_env("REMOTE_USER"); }
+ { return env_("REMOTE_USER"); }
 
     std::string request_method()
- { return meta_env("REQUEST_METHOD"); }
+ { return env_("REQUEST_METHOD"); }
 
     std::string script_name()
- { return meta_env("SCRIPT_NAME"); }
+ { return env_("SCRIPT_NAME"); }
 
     std::string server_name()
- { return meta_env("SERVER_NAME"); }
+ { return env_("SERVER_NAME"); }
 
     std::string server_port()
- { return meta_env("SERVER_PORT"); }
+ { return env_("SERVER_PORT"); }
 
     std::string server_protocol()
- { return meta_env("SERVER_PROTOCOL"); }
+ { return env_("SERVER_PROTOCOL"); }
 
     std::string server_software()
- { return meta_env("SERVER_SOFTWARE"); }
+ { return env_("SERVER_SOFTWARE"); }
 
 
     /// The role that the request is playing
@@ -576,6 +589,13 @@
       this->service.set_status(this->impl, status);
     }
 
+ /// Get the client connection associated with the request
+ typename implementation_type::connection_type&
+ client()
+ {
+ return this->service.client(this->impl);
+ }
+
     /// Set a user cookie
     /**
      * Note: this must be called before you have finished outputting

Modified: sandbox/SOC/2007/cgi/boost/cgi/cgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/cgi.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/cgi.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -12,12 +12,18 @@
 // Include all cgi-related headers only.
 #include "cgi/request.hpp"
 #include "cgi/service.hpp"
-//#include "cgi/service_impl.hpp"
-//#include "cgi/request_impl.hpp"
-//#include "cgi/gateway_impl.hpp"
-//#include "cgi/gateway_service.hpp"
 
 // Include headers common to all protocols
 #include "detail/common_headers.hpp"
 
+namespace cgi {
+ namespace cgi {
+
+ typedef ::cgi::cgi_request request;
+ //typedef cgi::cgi_service service; // to be added
+ using namespace ::cgi;
+
+ } // namespace cgi
+} // namespace cgi
+
 #endif // CGI_CGI_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/boost/cgi/cgi/service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/cgi/service.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/cgi/service.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -12,9 +12,9 @@
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/connections/stdio.hpp"
 #include "boost/cgi/connections/async_stdio.hpp"
+#include "boost/cgi/basic_protocol_service_fwd.hpp"
 #include "boost/cgi/gateway_impl/acgi_gateway_impl.hpp"
 #include "boost/cgi/gateway_service/acgi_gateway_service.hpp"
-#include "boost/cgi/basic_protocol_service.hpp"
 
 namespace cgi {
 

Added: sandbox/SOC/2007/cgi/boost/cgi/cookie.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/boost/cgi/cookie.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -0,0 +1,50 @@
+// -- cookie.hpp --
+//
+// Copyright (c) Darren Garvey 2007.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_COOKIE_HPP_INCLUDED__
+#define CGI_COOKIE_HPP_INCLUDED__
+
+#include <string>
+
+namespace cgi {
+
+ /// A `cookie` object that can be streamed to a `response` object
+ /**
+ * Either set the parameters in the constructor, or set them directly.
+ * Note: If you want to set the parameters individually, remember that each
+ * parameter must NOT have a trailing semi-colon!
+ */
+ struct cookie
+ {
+ cookie() {}
+
+ /// Delete the cookie named `_name`.
+ cookie(const std::string& _name)
+ : content(_name + "=")
+ , expires("Fri, 07 May 1824 16:30:00 GMT")
+ {
+ }
+
+ /// Create a cookie.
+ cookie(const std::string& _name, const std::string& _val
+ , const std::string& _expires = ""
+ , const std::string& _path = "")
+ : content(_name + "=" + _val)
+ , expires(_expires)
+ , path(_path)
+ {
+ }
+
+ std::string content;
+ std::string expires;
+ std::string path;
+ };
+
+} // namespace cgi
+
+#endif // CGI_COOKIE_HPP_INCLUDED__

Added: sandbox/SOC/2007/cgi/boost/cgi/header.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/boost/cgi/header.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -0,0 +1,44 @@
+// -- header.hpp --
+//
+// Copyright (c) Darren Garvey 2007.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_HEADER_HPP_INCLUDED__
+#define CGI_HEADER_HPP_INCLUDED__
+
+#include <string>
+
+namespace cgi {
+
+ struct header
+ {
+ header()
+ : content("\r\n")
+ {
+ }
+
+ header(const std::string& name, const std::string& val)
+ : content(name + ": " + val + "\r\n")
+ {
+ }
+
+ std::string content;
+ };
+
+ // Some shortcuts, to cut down on errors
+ header content_type(const std::string& str)
+ {
+ return header("Content-type", str);
+ }
+
+ header location(const std::string& url)
+ {
+ return header("Location", url);
+ }
+
+} // namespace cgi
+
+#endif // CGI_HEADER_HPP_INCLUDED__

Deleted: sandbox/SOC/2007/cgi/boost/cgi/reply.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/reply.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
+++ (empty file)
@@ -1,148 +0,0 @@
-// -- reply.hpp --
-//
-// Copyright (c) Darren Garvey 2007.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-////////////////////////////////////////////////////////////////
-#ifndef CGI_REPLY_HPP_INCLUDED__
-#define CGI_REPLY_HPP_INCLUDED__
-
-#include <string>
-
-#include "detail/push_options.hpp"
-#include "request_ostream.hpp"
-#include "buffer.hpp"
-
-namespace cgi {
-
- /// The reply class: a helper for replying to requests
-
- // The request_ostream is destined to become a basic_request_ostream
-//typedef request_ostream<> reply_;
-
-
- class reply
- : public cgi::request_ostream
- {
- public:
- reply(http::status_code sc = http::ok)
- : cgi::request_ostream(sc)
- {
- }
-
- reply(cgi::streambuf* buf, http::status_code sc = http::ok)
- : cgi::request_ostream(buf, sc)
- {
- }
-
- ~reply()
- {
- }
-
- /// Some helper functions for the basic CGI 1.1 meta-variables
- void auth_type(const std::string& value)
- {
- std::string str("Auth-type: ");
- str += value;
- this->headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
-
- void content_length(const std::string& value)
- {
- std::string str("Content-length: ");
- str += value;
- this->headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
-
- /* void auth_type(const std::string& value)
- {
- std::string str("Auth-type: " + value);
- headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
-
- void auth_type(const std::string& value)
- {
- std::string str("Auth-type: " + value);
- headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
-
- void auth_type(const std::string& value)
- {
- std::string str("Auth-type: " + value);
- headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
-
- void auth_type(const std::string& value)
- {
- std::string str("Auth-type: " + value);
- headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
-
- void auth_type(const std::string& value)
- {
- std::string str("Auth-type: " + value);
- headers_.push_back(cgi::buffer(str.c_str(), str.size()));
- }
- void content_length(const std::string& value)
- { return this->service.meta_env(this->impl, "CONTENT_LENGTH"); }
-
- void content_type(const std::string& value)
- { return this->service.meta_env(this->impl, "CONTENT_TYPE"); }
-
- void gateway_interface(const std::string& value)
- { return this->service.meta_env(this->impl, "GATEWAY_INTERFACE"); }
-
- void path_info(const std::string& value)
- { return this->service.meta_env(this->impl, "PATH_INFO"); }
-
- void path_translated(const std::string& value)
- { return this->service.meta_env(this->impl, "PATH_TRANSLATED"); }
-
- void query_string(const std::string& value)
- { return this->service.meta_env(this->impl, "QUERY_STRING"); }
-
- void remote_addr(const std::string& value)
- { return this->service.meta_env(this->impl, "REMOTE_ADDR"); }
-
- void remote_host(const std::string& value)
- { return this->service.meta_env(this->impl, "REMOTE_HOST"); }
-
- void remote_ident(const std::string& value)
- { return this->service.meta_env(this->impl, "REMOTE_IDENT"); }
-
- void remote_user(const std::string& value)
- { return this->service.meta_env(this->impl, "REMOTE_USER"); }
-
- void request_method(const std::string& value)
- { return this->service.meta_env(this->impl, "REQUEST_METHOD"); }
-
- void script_name(const std::string& value)
- { return this->service.meta_env(this->impl, "SCRIPT_NAME"); }
-
- void server_name(const std::string& value)
- { return this->service.meta_env(this->impl, "SERVER_NAME"); }
-
- void server_port(const std::string& value)
- { return this->service.meta_env(this->impl, "SERVER_PORT"); }
-
- void server_protocol(const std::string& value)
- { return this->service.meta_env(this->impl, "SERVER_PROTOCOL"); }
-
- void server_software(const std::string& value)
- { return this->service.meta_env(this->impl, "SERVER_SOFTWARE"); }
-
- private:
- char c_;
-
- };
-
-*/
- };
-
-} // namespace cgi
-
-#include "detail/pop_options.hpp"
-
-#endif // CGI_REPLY_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/boost/cgi/request_ostream.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/request_ostream.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/request_ostream.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -80,6 +80,7 @@
       : buffer_(new cgi::streambuf())
       , ostream_(buffer_.get())
       , http_status_(sc)
+ , headers_sent_(false)
     {
     }
 
@@ -162,6 +163,11 @@
     template<typename CommonGatewayRequest>
     void flush(CommonGatewayRequest& req)
     {
+ if (!headers_sent_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_sent_ = true;
+ }
       cgi::write(req, headers_);
       cgi::write(req, rdbuf()->data());
       // the above function will throw on an error
@@ -177,6 +183,11 @@
     boost::system::error_code& flush(CommonGatewayRequest& req
                                     , boost::system::error_code& ec)
     {
+ if (!headers_sent_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_sent_ = true;
+ }
       if(!cgi::write(req, rdbuf()->data(), ec))
         clear();
       return ec;
@@ -211,6 +222,11 @@
     template<typename CommonGatewayRequest, typename Handler>
     void async_flush(CommonGatewayRequest& req, Handler handler)
     {
+ if (!headers_sent_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_sent_ = true;
+ }
       cgi::async_write(req, rdbuf()->data()
                       , flush_handler<Handler>
                           (*this, handler, boost::arg<1>()));
@@ -256,7 +272,12 @@
     template<typename CommonGatewayRequest>
     void send(CommonGatewayRequest& req)
     {
- cgi::write(req, rdbuf()->data());
+ if (!headers_sent_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_sent_ = true;
+ }
+ cgi::write(req.client(), rdbuf()->data());
       req.set_status(http_status_);
     }
 
@@ -269,7 +290,12 @@
     boost::system::error_code& send(CommonGatewayRequest& req
                                    , boost::system::error_code& ec)
     {
- cgi::write(req, rdbuf()->data(), ec);
+ if (!headers_sent_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_sent_ = true;
+ }
+ cgi::write(req.client(), rdbuf()->data(), ec);
       req.set_status(http_status_);
       return ec;
     }
@@ -282,6 +308,11 @@
     void async_send(CommonGatewayRequest& req, Handler handler)
     {
       req.set_status(http_status_);
+ if (!headers_sent_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_sent_ = true;
+ }
       cgi::async_write(req, rdbuf()->data(), handler);
     }
 
@@ -291,7 +322,7 @@
       return static_cast<cgi::streambuf*>(ostream_.rdbuf());
     }
 
- void set_status(http::status_code& num)
+ void set_status(const http::status_code& num)
     {
       http_status_ = num;
     }
@@ -306,6 +337,7 @@
     boost::shared_ptr<cgi::streambuf> buffer_;
     std::ostream ostream_;
     http::status_code http_status_;
+ bool headers_sent_;
 
     template<typename T>
     friend request_ostream& operator<<(request_ostream&, const T&);

Added: sandbox/SOC/2007/cgi/boost/cgi/response.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/boost/cgi/response.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -0,0 +1,98 @@
+// -- response.hpp --
+//
+// Copyright (c) Darren Garvey 2007.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_RESPONSE_HPP_INCLUDED__
+#define CGI_RESPONSE_HPP_INCLUDED__
+
+#include <string>
+
+#include "boost/cgi/detail/push_options.hpp"
+#include "boost/cgi/request_ostream.hpp"
+#include "boost/cgi/buffer.hpp"
+#include "boost/cgi/cookie.hpp"
+#include "boost/cgi/header.hpp"
+
+namespace cgi {
+
+ /// The response class: a helper for responding to requests
+
+ // The request_ostream is destined to become a basic_request_ostream
+//typedef request_ostream<> response_;
+
+
+ class response
+ : public cgi::request_ostream
+ {
+ public:
+ response(http::status_code sc = http::ok)
+ : cgi::request_ostream(sc)
+ {
+ }
+
+ response(cgi::streambuf* buf, http::status_code sc = http::ok)
+ : cgi::request_ostream(buf, sc)
+ {
+ }
+
+ ~response()
+ {
+ }
+
+ /// Some helper functions for the basic CGI 1.1 meta-variables
+// void auth_type(const std::string& value)
+// {
+// std::string str("Auth-type: ");
+// str += value;
+// this->headers_.push_back(cgi::buffer(str.c_str(), str.size()));
+// }
+//
+// void content_length(const std::string& value)
+// {
+// std::string str("Content-length: ");
+// str += value;
+// this->headers_.push_back(cgi::buffer(str.c_str(), str.size()));
+// }
+
+ private:
+ template<typename T>
+ friend response& operator<<(response& resp, const T& t);
+ };
+
+ template<typename T>
+ response& operator<<(response& resp, const T& t)
+ {
+ resp.ostream_<< t;
+ return resp;
+ }
+
+ template<>
+ response& operator<<(response& resp, const header& hdr)
+ {
+ resp.headers_sent_ = true;
+ return resp<< hdr.content;
+ }
+
+ template<>
+ response& operator<<(response& resp, const cookie& c)
+ {
+ // Note: the 'set-cookie' isn't part of the cookie object since
+ // the cookie can also be set after the headers have been sent.
+ // See http://tinyurl.com/33znkj
+ resp<< "Set-cookie: " << c.content << ";";
+ if (!c.expires.empty())
+ resp<< c.expires << ";";
+ if (!c.path.empty())
+ resp<< c.path << ";";
+ return resp<< "\r\n";
+ }
+
+} // namespace cgi
+
+#include "detail/pop_options.hpp"
+
+#endif // CGI_RESPONSE_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/boost/cgi/status_type.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/boost/cgi/status_type.hpp (original)
+++ sandbox/SOC/2007/cgi/boost/cgi/status_type.hpp 2007-08-22 21:25:51 EDT (Wed, 22 Aug 2007)
@@ -17,7 +17,7 @@
     , loaded
     , ok
     , aborted
- , ended
+ , closed
     };
 
 } // namespace cgi


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk