Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-05-20 12:08:40


Author: drrngrvy
Date: 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
New Revision: 45579
URL: http://svn.boost.org/trac/boost/changeset/45579

Log:
Refactoring; lots of things moved - boost/cgi/ -> boost/cgi/common/; lots more cleanups that are long overdue.
Added:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/buffer.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/header.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/io_service.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/return.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/streambuf.hpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/
   sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi.hpp | 2
   sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp | 6
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp | 2
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_protocol_service.hpp | 5
   sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp | 2
   sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp | 19 +-
   sandbox/SOC/2007/cgi/trunk/boost/cgi/common/name.hpp | 3
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp | 35 ++-
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp | 30 +-
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp | 11
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/push_options.hpp | 7
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp | 2
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp | 6
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp | 6
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_acceptor_service.hpp | 6
   sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp | 25 +-
   sandbox/SOC/2007/cgi/trunk/boost/cgi/http/status_code.hpp | 143 ++++++++--------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/io_service.hpp | 18 -
   sandbox/SOC/2007/cgi/trunk/boost/cgi/response.hpp | 342 ++++++---------------------------------
   sandbox/SOC/2007/cgi/trunk/boost/cgi/status_type.hpp | 13 -
   20 files changed, 223 insertions(+), 460 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -29,7 +29,7 @@
    typedef acgi_request request;
    //typedef acgi_service service;
    //typedef acgi_acceptor acceptor;
- using namespace ::cgi; // **FIXME** this line must go.
+ //using namespace ::cgi; // **FIXME** this line must go.
    using namespace ::cgi::common; // import common namespace elements.
 
  } // namespace acgi

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/acgi/request_impl.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -11,8 +11,8 @@
 
 #include "boost/cgi/acgi/service.hpp"
 #include "boost/cgi/basic_client.hpp"
-#include "boost/cgi/detail/cgi_request_impl_base.hpp"
 #include "boost/cgi/connections/async_stdio.hpp"
+#include "boost/cgi/detail/cgi_request_impl_base.hpp"
 
 // Make this ProtocolService-independent
 
@@ -22,7 +22,7 @@
   class acgi_service_impl;
 
   class acgi_request_impl
- : public cgi_request_impl_base<common::async_stdio_connection>
+ : public detail::cgi_request_impl_base<common::async_stdio_connection>
   {
   public:
     typedef acgi_service protocol_service_type;
@@ -34,7 +34,7 @@
     client_type;
 
     acgi_request_impl()
- : cgi_request_impl_base<connection_type>()
+ : detail::cgi_request_impl_base<connection_type>()
     {
     }
 

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_client.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -10,7 +10,7 @@
 #define CGI_BASIC_CLIENT_HPP_INCLUDED__
 
 #include <boost/shared_ptr.hpp>
-
+///////////////////////////////////////////////////////////
 #include "boost/cgi/common/map.hpp"
 #include "boost/cgi/role_type.hpp"
 #include "boost/cgi/status_type.hpp"

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_protocol_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_protocol_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_protocol_service.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -11,11 +11,12 @@
 
 #include <set>
 #include <queue>
+///////////////////////////////////////////////////////////
 #include <boost/shared_ptr.hpp>
 #include <boost/asio/strand.hpp>
 #include <boost/detail/workaround.hpp>
-
-#include "boost/cgi/io_service.hpp"
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/io_service.hpp"
 #include "boost/cgi/io_service_provider.hpp"
 #include "boost/cgi/basic_request_fwd.hpp"
 #include "boost/cgi/detail/protocol_traits.hpp"

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/basic_request_acceptor.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -11,10 +11,10 @@
 
 #include <boost/noncopyable.hpp>
 #include <boost/system/error_code.hpp>
-
 #include <boost/asio/basic_io_object.hpp>
 #include <boost/asio/ip/basic_endpoint.hpp>
 #include <boost/asio/ip/tcp.hpp>
+///////////////////////////////////////////////////////////
 #include <boost/cgi/basic_protocol_service.hpp>
 #include "boost/cgi/detail/throw_error.hpp"
 

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/cgi/request_impl.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -11,15 +11,16 @@
 
 #include <map>
 #include <string>
-#include <boost/noncopyable.hpp>
+///////////////////////////////////////////////////////////
 #include <boost/shared_ptr.hpp>
-
-#include "boost/cgi/http/status_code.hpp"
-#include "boost/cgi/basic_client.hpp"
-#include "boost/cgi/connections/stdio.hpp"
+#include <boost/noncopyable.hpp>
+///////////////////////////////////////////////////////////
 #include "boost/cgi/role_type.hpp"
-#include "boost/cgi/status_type.hpp"
 #include "boost/cgi/common/map.hpp"
+#include "boost/cgi/status_type.hpp"
+#include "boost/cgi/basic_client.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/connections/stdio.hpp"
 #include "boost/cgi/detail/cgi_request_impl_base.hpp"
 
 // Make this ProtocolService-independent
@@ -38,7 +39,7 @@
    * restricted but if someone really wants to copy the data, then they can.
    */
   class cgi_request_impl
- : public cgi_request_impl_base<common::stdio_connection>
+ : public detail::cgi_request_impl_base<common::stdio_connection>
   {
   public:
     typedef ::cgi::common::basic_client<common::stdio_connection, tags::cgi> client_type;
@@ -50,12 +51,12 @@
      */
     template<typename ProtocolService>
     cgi_request_impl(ProtocolService& pserv)
- : cgi_request_impl_base<connection_type>(pserv)
+ : detail::cgi_request_impl_base<connection_type>(pserv)
     {
     }
 
     cgi_request_impl()
- : cgi_request_impl_base<connection_type>()
+ : detail::cgi_request_impl_base<connection_type>()
     {
     }
 

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/buffer.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/buffer.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,26 @@
+// -- buffer.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_BUFFER_HPP_INCLUDED__
+#define CGI_BUFFER_HPP_INCLUDED__
+
+#include <boost/asio/buffer.hpp>
+
+namespace cgi {
+ namespace common {
+
+ /// Import the Boost.Asio overloads.
+ using boost::asio::buffer;
+
+ } // namespace common
+
+ using common::buffer;
+
+} // namespace cgi
+
+#endif // CGI_HPP_INCLUDED__

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/cookie.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,148 @@
+// -- 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>
+#include <boost/system/error_code.hpp>
+#include <boost/tokenizer.hpp>
+
+namespace cgi {
+ namespace common {
+
+ template<typename CharT> struct basic_cookie;
+
+ // typedefs for common usage
+ typedef basic_cookie<char> cookie;
+ typedef basic_cookie<wchar_t> wcookie;
+
+ /// A `basic_cookie<>` object that can be (out-) streamed
+ /**
+ * 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!
+ *
+ * TODO
+ * - Data should be URL-encoded, or maybe provide an overload for url_decode
+ * that takes an HttpCookie?
+ * - Add from_string() ?
+ */
+ template<typename CharT>
+ struct basic_cookie
+ {
+ typedef CharT char_type;
+ typedef typename std::basic_string<CharT> string_type;
+
+ basic_cookie() {}
+
+ /// Delete the cookie named `_name`.
+ basic_cookie(const string_type& _name)
+ : name(_name)
+ , value()
+ , expires("Fri, 05-Jun-1989 15:30:00 GMT")
+ , path("/")
+ , secure(false)
+ , http_only(false)
+ {
+ }
+
+ /// Create a cookie.
+ basic_cookie(const string_type& _name, const string_type& _val
+ , const string_type& _expires = ""
+ , const string_type& _path = "/"
+ , const string_type& _domain = ""
+ , bool _secure = false
+ , bool HttpOnly = false)
+ : name(_name)
+ , value(_val)
+ , expires(_expires)
+ , path(_path)
+ , domain(_domain)
+ , secure(_secure)
+ , http_only(HttpOnly)
+ {
+ }
+
+ string_type name;
+ string_type value;
+ string_type expires;
+ string_type path;
+ string_type domain;
+ bool secure;
+ bool http_only;
+
+ /// Create a cookie from a const char*
+ /**
+ * Rules taken from: http://wp.netscape.com/newsref/std/cookie_spec.html
+ *
+ * Assumes:
+ * - Parts of the cookie are delimited by '; '. ie. if there is no space,
+ * or multiple spaces after the semi-colon, this function won't work...
+ */
+ /* Actually, I'm omitting these functions for now, just had a thought...
+ static basic_cookie<string_type>
+ from_string(const char* str, boost::system::error_code& ec)
+ {
+ typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+ boost::char_separator<char> sep(";=");
+ tokenizer tokens(str, sep);
+ for (tokenizer::iterator iter = tokens.begin();
+ iter != tokens.end(); ++iter)
+ {
+
+ }
+ return ck;
+ }
+
+ static basic_cookie<string_type> from_string(const char* str)
+ {
+ boost::system::error_code ec;
+ cookie ck = from_string(ec);
+ detail::throw_error(ec);
+ return ck;
+ }
+
+ static basic_cookie<string_type> from_string(std::string& str)
+ {
+ return from_string(str.c_str());
+ }
+
+ static basic_cookie<string_type>
+ from_string(std::string& str, boost::system::error_code& ec)
+ {
+ return from_string(str.c_str(), ec);
+ }
+ */
+
+ /// Make a string out of the cookie
+ string_type to_string()
+ {
+ string_type str(name + "=" + value);
+ if (!expires.empty()) str += ("; expires=" + expires);
+ if (!path.empty() ) str += ("; path=" + path);
+ if (!domain.empty() ) str += ("; domain=" + domain);
+ if ( secure ) str += "; secure";
+ if ( http_only ) str += "; HttpOnly";
+ return str;
+ }
+ };
+
+ } // namespace common
+} // namespace cgi
+
+
+template<typename OutStream, typename T>
+inline OutStream& operator<< (OutStream& os, cgi::common::basic_cookie<T>& ck)
+{
+ os<< ck.to_string();
+ return os;
+}
+
+#endif // CGI_COOKIE_HPP_INCLUDED__
+

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/header.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/header.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,139 @@
+// -- 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>
+#include <boost/lexical_cast.hpp>
+
+namespace cgi {
+ namespace common {
+
+ // **FIXME** (could include response_fwd.hpp really)...
+ template<typename CharT> class basic_response;
+
+ template<typename CharT>
+ struct basic_header
+ {
+ typedef CharT char_type;
+ typedef typename std::basic_string<CharT> string_type;
+
+ basic_header()
+ : content()
+ {
+ }
+
+ basic_header(const string_type& _content)
+ : content(_content)
+ {
+ }
+
+ basic_header(const string_type& name, const string_type& val)
+ : content(name + ": " + val)
+ {
+ }
+
+ /// Construct an header from a cookie.
+ basic_header(const basic_cookie<char_type>& ck)
+ : content("Set-cookie: " + ck.to_string())
+ {
+ }
+
+ string_type content;
+ };
+
+/*
+ template<typename StringT>
+ header<StringT>
+ make_header(const StringT& name, const StringT& val)
+ {
+ return basic_header<StringT>(name, val);
+ }* /
+
+ template<typename T, typename StringT>
+ T make_header(const StringT& name, const StringT& val)
+ {
+ return basic_header<StringT>(name, val);
+ }*/
+
+
+ //{ Some shortcuts, to cut down on typing errors.
+ template<typename CharT, typename StringT> basic_header<CharT>
+ content_type(StringT const& str)
+ {
+ return basic_header<CharT>("Content-type", str);
+ }
+
+ template<typename CharT> basic_header<CharT>
+ content_type(const CharT* str)
+ {
+ return basic_header<CharT>("Content-type", str);
+ }
+
+ template<typename CharT> basic_header<CharT>
+ content_encoding(std::basic_string<CharT> const& str)
+ {
+ return basic_header<CharT>("Content-encoding", str);
+ }
+
+ template<typename CharT, typename T> basic_header<CharT>
+ content_length(const T& t)
+ {
+ return basic_header<CharT>("Content-length",
+ boost::lexical_cast<std::basic_string<CharT> >(t));
+ }
+
+ template<typename CharT, typename T> basic_header<CharT>
+ content_length(T t)
+ {
+ return basic_header<CharT>("Content-length",
+ boost::lexical_cast<std::basic_string<CharT> >(t));
+ }
+
+ template<typename CharT> basic_header<CharT>
+ content_length(std::basic_string<CharT> const& str)
+ {
+ return basic_header<CharT>("Content-length", str);
+ }
+
+ template<typename CharT> basic_header<CharT>
+ content_length(basic_response<CharT>& resp)
+ {
+ return basic_header<CharT>("Content-length",
+ boost::lexical_cast<std::string>(resp.content_length()));
+ }
+
+ template<typename CharT> basic_header<CharT>
+ location(const CharT* url)
+ {
+ return basic_header<CharT>("Location", url);
+ }
+
+ template<typename CharT> basic_header<CharT>
+ location(std::basic_string<CharT> const& url)
+ {
+ return basic_header<CharT>("Location", url);
+ }
+
+ template<typename CharT, typename U> basic_header<CharT>
+ location(U const& url)
+ {
+ return basic_header<CharT>("Location", url);
+ }
+ //}
+
+ // typedefs for typical usage
+ typedef basic_header<char> header;
+ typedef basic_header<wchar_t> wheader;
+
+ } // namespace common
+} // namespace cgi
+
+#endif // CGI_HEADER_HPP_INCLUDED__
+

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/io_service.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/io_service.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,31 @@
+// -- common/io_service.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_COMMON_IO_SERVICE_HPP_INCLUDED__
+#define CGI_COMMON_IO_SERVICE_HPP_INCLUDED__
+
+//#if _MSC_VER > 1020
+//#pragma once
+//#endif
+
+#include <boost/asio/io_service.hpp>
+
+namespace cgi {
+ namespace common {
+
+ using boost::asio::io_service;
+
+ } // namespace common
+
+ // This should go?
+ using boost::asio::io_service;
+
+} // namespace cgi
+
+#endif // CGI_COMMON_IO_SERVICE_HPP_INCLUDED__
+

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/name.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/common/name.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/name.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -71,7 +71,8 @@
 template <typename CharT, typename Traits>
 std::basic_ostream<CharT, Traits>&
   operator<< (std::basic_ostream<CharT, Traits>& os
- , const std::basic_string<CharT, ichar_traits<CharT> >& str)
+ , const std::basic_string<CharT
+ , cgi::common::ichar_traits<CharT> >& str)
 {
   return os<< str.c_str();
 }

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/response.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,244 @@
+// -- 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 "boost/cgi/detail/push_options.hpp"
+
+#include <string>
+///////////////////////////////////////////////////////////
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/cookie.hpp"
+#include "boost/cgi/common/header.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/common/streambuf.hpp"
+#include "boost/cgi/basic_request_fwd.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+
+/// This mess outputs a default Content-type header if the user hasn't set any.
+/** **FIXME** Not implemented; not sure if it should be...
+ * BOOST_CGI_ADD_DEFAULT_HEADER should not persiste beyond this file.
+ *
+ * It basically works like (default first):
+ *
+ * Debug mode:
+ * - Append a "Content-type: text/plain" header;
+ * - If BOOST_CGI_DEFAULT_CONTENT_TYPE is defined, set that as the
+ * content-type;
+ * - If BOOST_CGI_NO_DEFAULT_CONTENT_TYPE is defined, do nothing.
+ *
+ * Release mode:
+ * - Do nothing.
+ */
+#if !defined(NDEBUG) && !defined(BOOST_CGI_NO_DEFAULT_CONTENT_TYPE)
+//{
+# if !defined(BOOST_CGI_DEFAULT_CONTENT_TYPE)
+# define BOOST_CGI_DEFAULT_CONTENT_TYPE "Content-type: text/plain"
+# endif // !defined(BOOST_CGI_DEFAULT_CONTENT_TYPE)
+//}
+# define BOOST_CGI_ADD_DEFAULT_HEADER \
+ if (headers_.empty()) \
+ headers_.push_back(BOOST_CGI_DEFAULT_CONTENT_TYPE"\r\n");
+#else
+# define BOOST_CGI_ADD_DEFAULT_HEADER
+#endif // !defined(NDEBUG) && !defined(BOOST_CGI_NO_DEFAULT_CONTENT_TYPE)
+
+
+namespace cgi {
+ namespace common {
+
+ /// The response class: a helper for responding to requests.
+ template<typename T>
+ class basic_response
+ {
+ public:
+ typedef T char_type;
+ typedef typename std::basic_string<T> string_type;
+ typedef typename std::basic_ostream<T> ostream_type;
+
+ basic_response(common::http::status_code sc = common::http::ok);
+
+ /// Construct with a particular buffer
+ /**
+ * Takes the buffer and uses it internally, does nothing with it on
+ * destruction.
+ */
+ basic_response(::cgi::common::streambuf* buf,
+ common::http::status_code sc = common::http::ok);
+
+ ~basic_response();
+
+ /// Clear the response buffer.
+ void clear();
+
+ /// Return the response to the 'just constructed' state.
+ void reset();
+
+ // provide this too?
+ std::size_t write(const char_type* str, std::size_t len);
+
+ std::size_t write(string_type const& str);
+
+ template<typename ConstBufferSequence>
+ std::size_t write(const ConstBufferSequence& buf);
+
+ /// Synchronously flush the data to the supplied SyncWriteStream
+ /**
+ * This call uses throwing semantics. ie. an exception will be thrown on
+ * any failure.
+ * If there is no error, the buffer is cleared.
+ */
+ template<typename SyncWriteStream>
+ void flush(SyncWriteStream& sws);
+
+ /// Synchronously flush the data via the supplied request
+ /**
+ * This call uses error_code semantics. ie. ec is set if an error occurs.
+ * If there is no error, the buffer is cleared.
+ */
+ template<typename SyncWriteStream>
+ boost::system::error_code
+ flush(SyncWriteStream& sws, boost::system::error_code& ec);
+
+ /// Synchronously send the data via the supplied request.
+ /**
+ * This call uses throwing semantics. ie. an exception will be thrown on
+ * any failure.
+ * Note: The data in the stream isn't cleared after this call.
+ */
+ template<typename SyncWriteStream>
+ void send(SyncWriteStream& sws);
+
+ /// Synchronously send the data via the supplied request.
+ /**
+ * This call will not throw, but will set `ec` such that `ec == true` if
+ * an error occurs. Details of the error are held in the `error_code`
+ * object.
+ */
+ template<typename SyncWriteStream>
+ boost::system::error_code
+ send(SyncWriteStream& sws, boost::system::error_code& ec);
+
+ /// Resend headers + content regardless of value of `headers_terminated_`.
+ template<typename SyncWriteStream>
+ void resend(SyncWriteStream& sws);
+
+ /// Asynchronously send the data through the supplied request
+ /**
+ * Note: This is quite crude at the moment and not as asynchronous as
+ * it could/should be. The data in the stream isn't cleared after
+ * this call.
+ */
+ template<typename AsyncWriteStream, typename Handler>
+ void async_send(AsyncWriteStream& aws, Handler handler);
+
+ template<typename AsyncWriteStream, typename Handler>
+ void do_async_send(AsyncWriteStream& aws, Handler handler);
+
+ /// Get the buffer associated with the stream
+ common::streambuf*
+ rdbuf();
+
+ /// Set the status code associated with the response.
+ basic_response<char_type>&
+ set_status(const http::status_code& num);
+
+ /// Get the status code associated with the response.
+ http::status_code& status();
+
+ /// Allow more headers to be added (WARNING: avoid using this).
+ void unterminate_headers();
+
+ /// Get the length of the body of the response
+ std::size_t content_length();
+
+ /// Add a header after appending the CRLF sequence.
+ basic_response<char_type>&
+ set_header(const string_type& value);
+
+ /// Format and add a header given name and value, appending CRLF.
+ basic_response<char_type>&
+ set_header(string_type const& name, string_type const& value);
+
+ void clear_headers();
+
+ void reset_headers();
+
+ bool headers_terminated() const;
+
+ // Is this really necessary?
+ void end_headers();
+
+ /// Get the ostream containing the response body.
+ ostream_type& ostream();
+ protected:
+ // Vector of all the headers, each followed by a CRLF
+ std::vector<string_type> headers_;
+
+ // The buffer is a shared_ptr, so you can keep it cached elsewhere.
+ boost::shared_ptr<common::streambuf> buffer_;
+
+ ostream_type ostream_;
+
+ http::status_code http_status_;
+
+ // True if no more headers can be appended.
+ bool headers_terminated_;
+
+ private:
+ // Send the response headers and mark that they've been sent.
+ template<typename ConstBufferSequence>
+ void prepare_headers(ConstBufferSequence& headers);
+ };
+
+ /// Typedefs for typical usage.
+ typedef basic_response<char> response;
+ typedef basic_response<wchar_t> wresponse; // **FIXME** (untested)
+
+ } // namespace common
+} // namespace cgi
+
+ /// Generic ostream template
+ template<typename CharT, typename T>
+ cgi::common::basic_response<CharT>&
+ operator<< (cgi::common::basic_response<CharT>& resp, const T& t);
+
+ template<typename CharT>
+ cgi::common::basic_response<CharT>&
+ operator<< (cgi::common::basic_response<CharT>& resp
+ , cgi::common::basic_header<CharT> const& hdr);
+
+ /// You can stream a cgi::cookie into a response.
+ /**
+ * This is just a shorthand way of setting a header that will set a
+ * client-side cookie.
+ *
+ * You cannot stream a cookie to a response after the headers have been
+ * terminated. In this case, an alternative could be to use the HTML tag:
+ * <meta http-equiv="Set-cookie" ...> (see http://tinyurl.com/3bxftv or
+ * http://tinyurl.com/33znkj), but this is outside the scope of this
+ * library.
+ */
+ template<typename charT, typename T>
+ cgi::common::basic_response<charT>&
+ operator<< (cgi::common::basic_response<charT>&
+ , cgi::common::basic_cookie<T>&);
+
+ template<typename charT, typename T>
+ cgi::common::basic_response<charT>&
+ operator<< (cgi::common::basic_response<charT>&
+ , cgi::common::http::status_code);
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#include "boost/cgi/impl/response.ipp"
+
+#endif // CGI_RESPONSE_HPP_INCLUDED__

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/return.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/return.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,63 @@
+// -- return.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)
+//
+////////////////////////////////////////////////////////////////
+//
+// A macro to make finishing up a request easier.
+// eg.
+// return_(resp, req, status);
+// is equivalent to
+// resp.send(req.client());
+// req.close(resp.status(), status);
+// return status;
+//
+#ifndef CGI_RETURN_HPP_INCLUDED__
+#define CGI_RETURN_HPP_INCLUDED__
+
+#include "boost/cgi/common/response.hpp"
+#include "boost/cgi/basic_request.hpp"
+
+namespace cgi {
+ namespace common {
+
+ template<typename Response, typename Request>
+ boost::system::error_code
+ return_helper(Response& resp, Request& req, int program_status)
+ {
+ boost::system::error_code ec;
+ resp.send(req.client(), ec);
+ if (ec) return ec;
+
+ req.close(resp.status(), program_status);
+
+ return ec;
+ }
+
+ } // namespace common
+} // namespace cgi
+
+/// If an error occurs during the sending or closing then `status` will be
+// incremented by the value of this macro.
+#ifndef BOOST_CGI_RETURN_ERROR_INCREMENT
+# define BOOST_CGI_RETURN_ERROR_INCREMENT 100
+#endif
+
+#define BOOST_CGI_RETURN(resp, req, status) \
+ if ( ::cgi::common::return_helper(resp, req, status)) \
+ /** error **/ \
+ return status + BOOST_CGI_RETURN_ERROR_INCREMENT; \
+ return status;
+
+namespace cgi {
+ namespace common {
+
+#define return_(resp, req, status) BOOST_CGI_RETURN(resp, req, status)
+
+ } // namespace common
+} // namespace cgi
+
+#endif // CGI_RETURN_HPP_INCLUDED__

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/common/streambuf.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/common/streambuf.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,25 @@
+// -- streambuf.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_STREAMBUF_HPP_INCLUDED__
+#define CGI_STREAMBUF_HPP_INCLUDED__
+
+#include <boost/asio/streambuf.hpp>
+
+namespace cgi {
+ namespace common {
+
+ using boost::asio::streambuf;
+
+ } // namespace common
+
+ using common::streambuf;
+
+} // namespace cgi
+
+#endif // CGI_STREAMBUF_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_request_impl_base.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -11,21 +11,20 @@
 
 #include <map>
 #include <string>
-#include <boost/noncopyable.hpp>
+///////////////////////////////////////////////////////////
 #include <boost/shared_ptr.hpp>
-
-#include "boost/cgi/http/status_code.hpp"
-#include "boost/cgi/connections/stdio.hpp"
+#include <boost/noncopyable.hpp>
+#include <boost/fusion/support.hpp>
+#include <boost/fusion/include/vector.hpp>
+///////////////////////////////////////////////////////////
 #include "boost/cgi/role_type.hpp"
-#include "boost/cgi/status_type.hpp"
 #include "boost/cgi/common/map.hpp"
-
-#include <boost/fusion/include/vector.hpp>
-#include <boost/fusion/support.hpp>
-
-// Make this ProtocolService-independent
+#include "boost/cgi/status_type.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/connections/stdio.hpp"
 
 namespace cgi {
+ namespace detail {
 
   //Forward declaration
   template<typename T>
@@ -54,16 +53,16 @@
       : stdin_parsed_(false)
       , stdin_data_read_(false)
       , stdin_bytes_left_(-1)
- , http_status_(http::ok)
- , request_status_(unloaded)
+ , http_status_(common::http::ok)
+ , request_status_(common::unloaded)
     {
     }
 
- bool stdin_parsed() { return stdin_parsed_; }
- http::status_code& http_status() { return http_status_; }
- status_type& status() { return request_status_; }
+ bool stdin_parsed() { return stdin_parsed_; }
+ common::http::status_code& http_status() { return http_status_; }
+ status_type& status() { return request_status_; }
 
- conn_ptr& connection() { return connection_; }
+ conn_ptr& connection() { return connection_; }
 
   public:
     //conn_ptr connection() { return connection_; }
@@ -76,12 +75,14 @@
     std::size_t stdin_bytes_left_;
   protected:
 
- http::status_code http_status_;
+ common::http::status_code http_status_;
     status_type request_status_;
 
     conn_ptr connection_;
   };
 
+ } // namespace detail
 } // namespace cgi
 
 #endif // CGI_CGI_REQUEST_IMPL_BASE_HPP_INCLUDED__
+

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/cgi_service_impl_base.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -13,32 +13,27 @@
 
 #include <string>
 #include <cstdlib>
+///////////////////////////////////////////////////////////
 #include <boost/assert.hpp>
 #include <boost/regex.hpp>
 #include <boost/tokenizer.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/algorithm/string/find.hpp>
-
-#include "boost/cgi/common/map.hpp"
-#include "boost/cgi/basic_client.hpp"
+///////////////////////////////////////////////////////////
 #include "boost/cgi/role_type.hpp"
+#include "boost/cgi/common/map.hpp"
 #include "boost/cgi/status_type.hpp"
-#include "boost/cgi/detail/extract_params.hpp"
-#include "boost/cgi/detail/save_environment.hpp"
+#include "boost/cgi/basic_client.hpp"
 #include "boost/cgi/common/form_part.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
-
 #include "boost/cgi/common/form_parser.hpp"
 #include "boost/cgi/common/request_base.hpp"
+#include "boost/cgi/detail/extract_params.hpp"
+#include "boost/cgi/detail/save_environment.hpp"
 
 namespace cgi {
-
- namespace detail {
-
-
- } // namespace detail
-
+// **FIXME** Wrong namespace (should be cgi::detail?).
 
   template<typename RequestImplType>
   class cgi_service_impl_base
@@ -87,7 +82,7 @@
      */
     bool is_open(implementation_type& impl)
     {
- return impl.status() >= aborted;
+ return impl.status() >= common::aborted;
     }
 
     /// Return the connection associated with the request
@@ -99,9 +94,10 @@
 
     int request_id(implementation_type& impl) { return 1; }
 
- int close(implementation_type& impl, http::status_code& http_s, int status)
+ int close(implementation_type& impl, common::http::status_code& http_s
+ , int status)
     {
- impl.status() = closed;
+ impl.status() = common::closed;
       impl.http_status() = http_s;
       return status;
     }
@@ -129,7 +125,7 @@
       if (ec) return ec;
 
       this->parse_cookie_vars(impl, ec);
- impl.status() = loaded;
+ impl.status() = common::loaded;
 
       //BOOST_ASSERT(impl.status() >= loaded);
 
@@ -174,7 +170,7 @@
     }
 
     /// Set the http status (this does nothing for aCGI)
- void set_status(implementation_type& impl, http::status_code&)
+ void set_status(implementation_type& impl, common::http::status_code&)
     {
     }
 

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/common_headers.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -12,17 +12,18 @@
 // #include all protocol-independent headers only. Protocol-specific
 // headers can just include this after other headers.
 
-#include "boost/cgi/buffer.hpp"
+#include "boost/cgi/common/buffer.hpp"
 #include "boost/cgi/common/map.hpp"
 #include "boost/cgi/io_service.hpp"
-#include "boost/cgi/streambuf.hpp"
+#include "boost/cgi/common/streambuf.hpp"
 #include "boost/cgi/basic_request.hpp"
 //#include "boost/cgi/basic_request_acceptor.hpp"
-#include "boost/cgi/response.hpp"
+#include "boost/cgi/common/response.hpp"
 //#include "boost/cgi/logger.hpp"
 #include "boost/cgi/read.hpp"
 #include "boost/cgi/write.hpp"
-#include "boost/cgi/header.hpp"
-#include "boost/cgi/return.hpp"
+#include "boost/cgi/common/header.hpp"
+#include "boost/cgi/common/return.hpp"
+#include "boost/cgi/http/status_code.hpp"
 
 #endif // CGI_CGI_CGI_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/push_options.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/push_options.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/push_options.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -14,3 +14,10 @@
 //#pragma warning (disable:4996)
 
 //#endif
+
+#if defined(BOOST_CGI_BUILD_LIB)
+# define BOOST_CGI_INLINE
+#else
+# define BOOST_CGI_INLINE inline
+#endif
+

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -20,7 +20,7 @@
 
 namespace cgi {
  namespace fcgi {
- using namespace ::cgi; // **FIXME** this must go.
+ //using namespace ::cgi; // **FIXME** this must go.
    using namespace ::cgi::common; // import common elements.
  } // namespace fcgi
 } // namespace cgi

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/acceptor_service_impl.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -19,14 +19,12 @@
 #include <boost/thread.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/system/error_code.hpp>
-
-//#include "is_async.hpp"
-#include "boost/cgi/io_service.hpp"
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/io_service.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/detail/protocol_traits.hpp"
 #include "boost/cgi/basic_protocol_service_fwd.hpp"
 #include "boost/cgi/detail/service_base.hpp"
-//#include "service_selector.hpp"
 #include "boost/cgi/fcgi/request.hpp"
 
 namespace cgi {

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/client.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -10,17 +10,19 @@
 #define CGI_FCGI_CLIENT_HPP_INCLUDED__
 
 #include <vector>
+///////////////////////////////////////////////////////////
 #include <boost/shared_ptr.hpp>
 #include <boost/logic/tribool.hpp>
 #include <boost/asio/buffer.hpp>
+///////////////////////////////////////////////////////////
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/common/map.hpp"
-#include "boost/cgi/io_service.hpp"
+#include "boost/cgi/common/io_service.hpp"
 #include "boost/cgi/basic_client.hpp"
 #include "boost/cgi/connections/shareable_tcp_socket.hpp"
 #include "boost/cgi/fcgi/specification.hpp"
 #include "boost/cgi/read.hpp"
-#include "boost/cgi/buffer.hpp"
+#include "boost/cgi/common/buffer.hpp"
 #include "boost/cgi/error.hpp"
 //#include "boost/cgi/fcgi/request_fwd.hpp"
 #include "boost/cgi/detail/protocol_traits.hpp"

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_acceptor_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_acceptor_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_acceptor_service.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -11,14 +11,12 @@
 #include "boost/cgi/detail/push_options.hpp"
 
 #include <boost/utility/enable_if.hpp>
-
-//#include "is_async.hpp"
-#include "boost/cgi/io_service.hpp"
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/io_service.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 #include "boost/cgi/detail/protocol_traits.hpp"
 #include "boost/cgi/basic_protocol_service_fwd.hpp"
 #include "boost/cgi/detail/service_base.hpp"
-//#include "service_selector.hpp"
 #include "boost/cgi/fcgi/acceptor_service_impl.hpp"
 
 namespace cgi {

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/fcgi/request_service.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -9,20 +9,21 @@
 #ifndef CGI_FCGI_REQUEST_SERVICE_HPP_INCLUDED__
 #define CGI_FCGI_REQUEST_SERVICE_HPP_INCLUDED__
 
+#include <boost/fusion/support.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/fusion/include/vector.hpp>
-#include <boost/fusion/support.hpp>
 ////////////////////////////////////////////////////////////////
-#include "boost/cgi/common/map.hpp"
-#include "boost/cgi/common/source_enums.hpp"
-#include "boost/cgi/common/request_base.hpp"
 #include "boost/cgi/tags.hpp"
 #include "boost/cgi/read.hpp"
 #include "boost/cgi/role_type.hpp"
-#include "boost/cgi/io_service.hpp"
+#include "boost/cgi/common/map.hpp"
+#include "boost/cgi/fcgi/client.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/common/io_service.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
+#include "boost/cgi/common/source_enums.hpp"
+#include "boost/cgi/common/request_base.hpp"
 #include "boost/cgi/detail/service_base.hpp"
-#include "boost/cgi/fcgi/client.hpp"
 #include "boost/cgi/common/form_parser.hpp"
 
 namespace cgi {
@@ -81,7 +82,7 @@
       implementation_type()
         : client_()
         , stdin_parsed_(false)
- , http_status_(http::no_content)
+ , http_status_(::cgi::common::http::no_content)
         , request_status_(unloaded)
         , request_role_(spec_detail::ANY)
         , all_done_(false)
@@ -93,7 +94,7 @@
       client_type client_;
 
       bool stdin_parsed_;
- http::status_code http_status_;
+ ::cgi::common::http::status_code http_status_;
       status_type request_status_;
       fcgi::spec_detail::role_t request_role_;
 
@@ -167,7 +168,7 @@
     }
 
     /// Close the request.
- int close(implementation_type& impl, http::status_code& hsc
+ int close(implementation_type& impl, ::cgi::common::http::status_code& hsc
               , int program_status)
     {
       impl.all_done_ = true;
@@ -175,7 +176,7 @@
       return program_status;
     }
 
- int close(implementation_type& impl, http::status_code& hsc
+ int close(implementation_type& impl, ::cgi::common::http::status_code& hsc
              , int program_status, boost::system::error_code& ec)
     {
       impl.all_done_ = true;
@@ -186,8 +187,8 @@
     void clear(implementation_type& impl)
     {
       BOOST_ASSERT
- ( impl.request_status_ < activated
- && impl.request_status_ > ok
+ ( impl.request_status_ < common::activated
+ && impl.request_status_ > common::ok
        && "Are you trying to clear() a request without closing it?"
       );
                 

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/http/status_code.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/http/status_code.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/http/status_code.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -10,77 +10,82 @@
 #define CGI_HTTP_STATUS_CODE_HPP_INCLUDED__
 
 namespace cgi {
- namespace http {
+ namespace common {
+ namespace http {
 
- /// Standard HTTP status codes
- /**
- * See http://tools.ietf.org/html/rfc2616#section-10
- */
- enum status_code
- {
- /// Informational codes
- continue_ = 100, // note the trailing underscore
- switching_protocols,
- processing,
-
- /// Success codes
- ok = 200,
- created,
- accepted,
- non_authorative_information,
- no_content,
- reset_content,
- partial_content,
- multi_status,
-
- /// Redirect codes
- multiple_choices = 300,
- moved_permanently,
- found,
- see_other,
- not_modified,
- use_proxy,
- switch_proxy,
- temporary_redirect,
-
- /// Domain error codes
- bad_request = 400,
- unauthorized,
- payment_required,
- forbidden,
- not_found,
- method_not_allowed,
- not_acceptable,
- proxy_authentication_required,
- request_timeout,
- conflict,
- gone,
- length_required,
- precondition_failed,
- request_entity_too_large,
- request_uri_too_long,
- unsupported_media_type,
- request_range_not_satisfiable,
- expectation_failed,
- unprocessable_entity = 422,
- locked,
- failed_dependency,
- unordered_collection,
- upgrade_required,
- retry_with = 449,
-
- /// Internal error codes
- internal_server_error = 500,
- not_implemented,
- bad_gateway,
- service_unavailable,
- gateway_timeout,
- http_version_not_supported,
- insufficient_storage,
- bandwidth_limit_exceeded = 509
- };
+ /// Standard HTTP status codes
+ /**
+ * See http://tools.ietf.org/html/rfc2616#section-10
+ */
+ enum status_code
+ {
+ /// Informational codes
+ continue_ = 100, // note the trailing underscore
+ switching_protocols,
+ processing,
+
+ /// Success codes
+ ok = 200,
+ created,
+ accepted,
+ non_authorative_information,
+ no_content,
+ reset_content,
+ partial_content,
+ multi_status,
+
+ /// Redirect codes
+ multiple_choices = 300,
+ moved_permanently,
+ found,
+ see_other,
+ not_modified,
+ use_proxy,
+ switch_proxy,
+ temporary_redirect,
+
+ /// Domain error codes
+ bad_request = 400,
+ unauthorized,
+ payment_required,
+ forbidden,
+ not_found,
+ method_not_allowed,
+ not_acceptable,
+ proxy_authentication_required,
+ request_timeout,
+ conflict,
+ gone,
+ length_required,
+ precondition_failed,
+ request_entity_too_large,
+ request_uri_too_long,
+ unsupported_media_type,
+ request_range_not_satisfiable,
+ expectation_failed,
+ unprocessable_entity = 422,
+ locked,
+ failed_dependency,
+ unordered_collection,
+ upgrade_required,
+ retry_with = 449,
+
+ /// Internal error codes
+ internal_server_error = 500,
+ not_implemented,
+ bad_gateway,
+ service_unavailable,
+ gateway_timeout,
+ http_version_not_supported,
+ insufficient_storage,
+ bandwidth_limit_exceeded = 509
+ };
+
+ } // namespace http
+ } // namespace common
+
+ using namespace common::http; // **FIXME**
 
- } // namespace http
 } // namespace cgi
 
 #endif // CGI_HTTP_STATUS_CODE_HPP_INCLUDED__

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/impl/response.ipp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -0,0 +1,437 @@
+// -- impl/response.ipp --
+//
+// 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)
+//
+////////////////////////////////////////////////////////////////
+//
+// The implementation for common::basic_response<>.
+//
+#ifndef CGI_RESPONSE_IPP_INCLUDED__
+#define CGI_RESPONSE_IPP_INCLUDED__
+
+#include "boost/cgi/detail/push_options.hpp"
+
+#include <string>
+///////////////////////////////////////////////////////////
+#include <boost/foreach.hpp>
+#include <boost/bind.hpp>
+///////////////////////////////////////////////////////////
+#include "boost/cgi/write.hpp"
+#include "boost/cgi/common/buffer.hpp"
+#include "boost/cgi/common/cookie.hpp"
+#include "boost/cgi/common/header.hpp"
+#include "boost/cgi/http/status_code.hpp"
+#include "boost/cgi/common/streambuf.hpp"
+#include "boost/cgi/basic_request_fwd.hpp"
+#include "boost/cgi/detail/throw_error.hpp"
+
+
+namespace cgi {
+ namespace common {
+
+ template<typename T>
+ BOOST_CGI_INLINE basic_response<T>::basic_response(
+ common::http::status_code sc)
+ : buffer_(new ::cgi::streambuf())
+ , ostream_(buffer_.get())
+ , http_status_(sc)
+ , headers_terminated_(false)
+ {
+ }
+
+ /// Construct with a particular buffer
+ /**
+ * Takes the buffer and uses it internally, does nothing with it on
+ * destruction.
+ */
+ template<typename T> BOOST_CGI_INLINE
+ basic_response<T>::basic_response(::cgi::streambuf* buf,
+ common::http::status_code sc)
+ : ostream_(buf)
+ , http_status_(sc)
+ {
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ basic_response<T>::~basic_response()
+ {
+ }
+
+ /// Clear the response buffer.
+ template<typename T> BOOST_CGI_INLINE
+ void basic_response<T>::clear()
+ {
+ ostream_.clear();
+ headers_.clear();
+ headers_terminated_ = false;
+ }
+
+ /// Return the response to the 'just constructed' state.
+ template<typename T> BOOST_CGI_INLINE
+ void basic_response<T>::reset()
+ {
+ clear();
+ headers_terminated_ = false;
+ }
+
+ // provide this too?
+ template<typename T> BOOST_CGI_INLINE
+ std::size_t basic_response<T>::write(const char_type* str, std::size_t len)
+ {
+ ostream_.write(str, len);
+ return len;
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ std::size_t basic_response<T>::write(std::basic_string<T> const& str)
+ {
+ return write(str.c_str(), str.size());
+ }
+
+ template<typename T>
+ template<typename ConstBufferSequence> BOOST_CGI_INLINE
+ std::size_t basic_response<T>::write(const ConstBufferSequence& buf)
+ {
+ return ostream_.write(buf.begin(), buf.end());
+ }
+
+ /// Synchronously flush the data to the supplied SyncWriteStream
+ /**
+ * This call uses throwing semantics. ie. an exception will be thrown on
+ * any failure.
+ * If there is no error, the buffer is cleared.
+ */
+ template<typename T>
+ template<typename SyncWriteStream> BOOST_CGI_INLINE
+ void basic_response<T>::flush(SyncWriteStream& sws)
+ {
+ boost::system::error_code ec;
+ flush(sws, ec);
+ detail::throw_error(ec);
+ }
+
+ /// Synchronously flush the data via the supplied request
+ /**
+ * This call uses error_code semantics. ie. ec is set if an error occurs.
+ * If there is no error, the buffer is cleared.
+ */
+ template<typename T>
+ template<typename SyncWriteStream> BOOST_CGI_INLINE
+ boost::system::error_code
+ basic_response<T>::flush(SyncWriteStream& sws, boost::system::error_code& ec)
+ {
+ if (!headers_terminated_)
+ {
+ std::vector<boost::asio::const_buffer> headers;
+ prepare_headers(headers);//, ec);
+ common::write(sws, headers, boost::asio::transfer_all(), ec);
+ if (ec)
+ return ec;
+ }
+
+ std::size_t bytes_written
+ = common::write(sws, buffer_->data(), boost::asio::transfer_all(), ec);
+ if (!ec)
+ buffer_->consume(bytes_written);
+
+ return ec;
+ }
+
+ /// Synchronously send the data via the supplied request.
+ /**
+ * This call uses throwing semantics. ie. an exception will be thrown on
+ * any failure.
+ * Note: The data in the stream isn't cleared after this call.
+ */
+ template<typename T>
+ template<typename SyncWriteStream> BOOST_CGI_INLINE
+ void basic_response<T>::send(SyncWriteStream& sws)
+ {
+ boost::system::error_code ec;
+ send(sws, ec);
+ detail::throw_error(ec);
+ }
+
+ /// Synchronously send the data via the supplied request.
+ /**
+ * This call will not throw, but will set `ec` such that `ec == true` if
+ * an error occurs. Details of the error are held in the `error_code`
+ * object.
+ */
+ template<typename T>
+ template<typename SyncWriteStream> BOOST_CGI_INLINE
+ boost::system::error_code
+ basic_response<T>::send(SyncWriteStream& sws
+ , boost::system::error_code& ec)
+ {
+ if (!headers_terminated_)
+ {
+ /* Not sure if streambuf allows this
+ *
+ // We want to be able to keep adding to a response, calling send() on
+ // it whenever, without resending the headers. Call resend() if you
+ // want to send the whole response again.
+ headers_terminated_ = true;
+ */
+ std::vector<boost::asio::const_buffer> headers;
+ prepare_headers(headers);//, ec)
+ common::write(sws, headers, boost::asio::transfer_all(), ec);
+ }
+
+ common::write(sws, buffer_->data(), boost::asio::transfer_all(), ec);
+
+ return ec;
+ }
+
+ /// Resend headers + content regardless of value of `headers_terminated_`.
+ template<typename T>
+ template<typename SyncWriteStream> BOOST_CGI_INLINE
+ void basic_response<T>::resend(SyncWriteStream& sws)
+ {
+ std::vector<boost::asio::const_buffer> headers;
+ prepare_headers(headers);//, ec)
+ common::write(sws, headers);
+
+ common::write(sws, buffer_->data());
+ }
+
+ /// Asynchronously send the data through the supplied request
+ /**
+ * Note: This is quite crude at the moment and not as asynchronous as
+ * it could/should be. The data in the stream isn't cleared after
+ * this call.
+ */
+ template<typename T>
+ template<typename AsyncWriteStream, typename Handler> BOOST_CGI_INLINE
+ void basic_response<T>::async_send(AsyncWriteStream& aws, Handler handler)
+ {
+ aws.io_service().post(
+ boost::bind(&basic_response<char_type>::do_async_send, aws, handler)
+ );
+ }
+
+ template<typename T>
+ template<typename AsyncWriteStream, typename Handler> BOOST_CGI_INLINE
+ void basic_response<T>::do_async_send(AsyncWriteStream& aws, Handler handler)
+ {
+ //req.set_status(http_status_);
+ /*
+ if (!headers_terminated_)
+ {
+ ostream_<< "Content-type: text/plain\r\n\r\n";
+ headers_terminated_ = true;
+ }
+ */
+ common::async_write(aws, rdbuf()->data(), handler);
+ }
+
+ /// Get the buffer associated with the stream
+ template<typename T> BOOST_CGI_INLINE
+ common::streambuf*
+ basic_response<T>::rdbuf()
+ {
+ return static_cast<common::streambuf*>(ostream_.rdbuf());
+ }
+
+ /// Set the status code associated with the response.
+ template<typename T> BOOST_CGI_INLINE
+ basic_response<T>&
+ basic_response<T>::set_status(const http::status_code& num)
+ {
+ http_status_ = num;
+ return *this;
+ }
+
+ /// Get the status code associated with the response.
+ template<typename T> BOOST_CGI_INLINE
+ http::status_code&
+ basic_response<T>::status()
+ {
+ return http_status_;
+ }
+
+ /// Allow more headers to be added (WARNING: avoid using this).
+ template<typename T> BOOST_CGI_INLINE
+ void basic_response<T>::unterminate_headers()
+ {
+ headers_terminated_ = false;
+ }
+
+ /// Get the length of the body of the response
+ template<typename T> BOOST_CGI_INLINE
+ std::size_t
+ basic_response<T>::content_length()
+ {
+ return rdbuf()->size();
+ }
+
+ /// Add a header after appending the CRLF sequence.
+ template<typename T> BOOST_CGI_INLINE
+ basic_response<T>&
+ basic_response<T>::set_header(
+ typename basic_response<T>::string_type const& value)
+ {
+ BOOST_ASSERT(!headers_terminated_);
+ headers_.push_back(value + "\r\n");
+ return *this;
+ }
+
+ /// Format and add a header given name and value, appending CRLF.
+ template<typename T> BOOST_CGI_INLINE
+ basic_response<T>&
+ basic_response<T>::set_header(
+ typename basic_response<T>::string_type const& name
+ , typename basic_response<T>::string_type const& value)
+ {
+ BOOST_ASSERT(!headers_terminated_);
+ headers_.push_back(name + ": " + value + "\r\n");
+ return *this;
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ void basic_response<T>::clear_headers()
+ {
+ BOOST_ASSERT(!headers_terminated_);
+ headers_.clear();
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ void basic_response<T>::reset_headers()
+ {
+ headers_.clear();
+ headers_terminated_ = false;
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ bool basic_response<T>::headers_terminated() const
+ {
+ return headers_terminated_;
+ }
+
+ // Is this really necessary?
+ template<typename T> BOOST_CGI_INLINE
+ void basic_response<T>::end_headers()
+ {
+ headers_terminated_ = true;
+ }
+
+ /// Get the ostream containing the response body.
+ template<typename T> BOOST_CGI_INLINE
+ typename basic_response<T>::ostream_type&
+ basic_response<T>::ostream() { return ostream_; }
+
+ // Send the response headers and mark that they've been sent.
+ template<typename T>
+ template<typename ConstBufferSequence> BOOST_CGI_INLINE
+ void basic_response<T>::prepare_headers(ConstBufferSequence& headers)
+ {
+ BOOST_CGI_ADD_DEFAULT_HEADER
+
+ // Terminate the headers.
+ if (!headers_terminated_)
+ headers_.push_back("\r\n");
+
+ //{ Construct a ConstBufferSequence out of the headers we have.
+ //std::vector<boost::asio::const_buffer> headers;
+ typedef typename std::vector<string_type>::iterator iter;
+ for (iter i(headers_.begin()), e(headers_.end()); i != e; ++i)
+ {
+ headers.push_back(common::buffer(*i));
+ }
+ //}
+
+ headers_terminated_ = true;
+ //return ec;
+ }
+
+ } // namespace common
+} // namespace cgi
+
+ /// Generic ostream template
+ template<typename T, typename U> BOOST_CGI_INLINE
+ cgi::common::basic_response<T>&
+ operator<< (cgi::common::basic_response<T>& resp, const U& u)
+ {
+ resp.ostream()<< u;
+ return resp;
+ }
+
+ /// You can stream a cgi::header into a response.
+ /**
+ * This is just a more convenient way of doing:
+ *
+ * ``
+ * resp.set_header(header_content)
+ * ``
+ *
+ * [tip
+ * If you stream a default-constructed header to a response, it
+ * 'terminates' the headers. ie. You can do this if you want to ensure
+ * no further headers are added to the response. It has no other side-
+ * effects; for instance, it won't write any data to the client.
+ * ]
+ */
+ template<typename T> BOOST_CGI_INLINE
+ cgi::common::basic_response<T>&
+ operator<< (cgi::common::basic_response<T>& resp
+ , cgi::common::basic_header<T> const& hdr)
+ {
+ if (hdr.content.empty()) {
+ resp.end_headers();
+ return resp;
+ }else{
+ // We shouldn't allow headers to be sent after they're explicitly ended.
+ BOOST_ASSERT(!resp.headers_terminated());
+ resp.set_header(hdr.content);
+ return resp;
+ }
+ }
+
+ /// You can stream a cgi::cookie into a response.
+ /**
+ * This is just a shorthand way of setting a header that will set a
+ * client-side cookie.
+ *
+ * You cannot stream a cookie to a response after the headers have been
+ * terminated. In this case, an alternative could be to use the HTML tag:
+ * <meta http-equiv="Set-cookie" ...> (see http://tinyurl.com/3bxftv or
+ * http://tinyurl.com/33znkj), but this is outside the scope of this
+ * library.
+ */
+ template<typename T> BOOST_CGI_INLINE
+ cgi::common::basic_response<T>&
+ operator<< (cgi::common::basic_response<T>& resp
+ , cgi::common::basic_cookie<T> ck)
+ {
+ BOOST_ASSERT(!resp.headers_terminated());
+ resp.set_header("Set-cookie", ck.to_string());
+ return resp;
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ cgi::common::basic_response<T>&
+ operator<< (cgi::common::basic_response<T>& resp
+ , cgi::common::basic_cookie<T> const& ck)
+ {
+ BOOST_ASSERT(!resp.headers_terminated());
+ resp.set_header("Set-cookie", ck.to_string());
+ return resp;
+ }
+
+ template<typename T> BOOST_CGI_INLINE
+ cgi::common::basic_response<T>&
+ operator<< (cgi::common::basic_response<T>& resp
+ , cgi::common::http::status_code status)
+ {
+ BOOST_ASSERT(!resp.headers_terminated());
+ return resp.set_status(status);
+ }
+
+#undef BOOST_CGI_ADD_DEFAULT_HEADER
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_RESPONSE_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/io_service.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/io_service.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/io_service.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -9,22 +9,6 @@
 #ifndef CGI_IO_SERVICE_HPP_INCLUDED__
 #define CGI_IO_SERVICE_HPP_INCLUDED__
 
-//#if _MSC_VER > 1020
-//#pragma once
-//#endif
-
-#include <boost/asio/io_service.hpp>
-
-namespace cgi {
- namespace common {
-
- using boost::asio::io_service;
-
- } // namespace common
-
- // This should go?
- using boost::asio::io_service;
-
-} // namespace cgi
+#include "boost/cgi/common/io_service.hpp"
 
 #endif // CGI_IO_SERVICE_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/response.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/response.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/response.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -12,24 +12,20 @@
 #include "boost/cgi/detail/push_options.hpp"
 
 #include <string>
-#include <fstream> // only for testing
-
+///////////////////////////////////////////////////////////
 #include <boost/foreach.hpp>
 #include <boost/bind.hpp>
-
-//#include "boost/cgi/request_ostream.hpp"
-#include "boost/cgi/buffer.hpp"
-#include "boost/cgi/cookie.hpp"
-#include "boost/cgi/header.hpp"
-#include "boost/cgi/write.hpp"
+///////////////////////////////////////////////////////////
+#include "boost/cgi/common/cookie.hpp"
+#include "boost/cgi/common/header.hpp"
 #include "boost/cgi/basic_request_fwd.hpp"
 #include "boost/cgi/http/status_code.hpp"
-#include "boost/cgi/streambuf.hpp"
+#include "boost/cgi/common/streambuf.hpp"
 #include "boost/cgi/detail/throw_error.hpp"
 
 /// This mess outputs a default Content-type header if the user hasn't set any.
 /** **FIXME** Not implemented; not sure if it should be...
- * BOOST_CGI_ADD_DEFAULT_HEADER should not persiste beyond this file.
+ * BOOST_CGI_ADD_DEFAULT_HEADER should not persiste into user-code.
  *
  * It basically works like (default first):
  *
@@ -68,64 +64,30 @@
     typedef typename std::basic_string<T> string_type;
     typedef typename std::basic_ostream<T> ostream_type;
 
- basic_response(http::status_code sc = http::ok)
- : buffer_(new ::cgi::streambuf())
- , ostream_(buffer_.get())
- , http_status_(sc)
- , headers_terminated_(false)
- {
- }
+ basic_response(http::status_code sc = http::ok);
 
     /// Construct with a particular buffer
     /**
      * Takes the buffer and uses it internally, does nothing with it on
      * destruction.
      */
- basic_response(::cgi::streambuf* buf, http::status_code sc = http::ok)
- : /*request_(NULL)
- , */ostream_(buf)
- , http_status_(sc)
- {
- }
-
- ~basic_response()
- {
- }
+ basic_response(::cgi::streambuf* buf, http::status_code sc = http::ok);
+
+ ~basic_response();
 
     /// Clear the response buffer.
- void clear()
- {
- ostream_.clear();
- headers_.clear();
- headers_terminated_ = false;
- //buffer_->consume(
- }
+ void clear();
 
     /// Return the response to the 'just constructed' state.
- void reset()
- {
- clear();
- headers_terminated_ = false;
- }
+ void reset();
 
     // provide this too?
- std::size_t write(const char_type* str, std::size_t len)
- {
- ostream_.write(str, len);
- return len;
- }
-
- std::size_t write(const string_type& str)
- {
- return write(str.c_str(), str.size());
- }
+ std::size_t write(const char_type* str, std::size_t len);
+
+ std::size_t write(string_type const& str);
 
     template<typename ConstBufferSequence>
- std::size_t write(const ConstBufferSequence& buf)
- {
- return ostream_.write(buf.begin(), buf.end());
- //return buf.size();
- }
+ std::size_t write(const ConstBufferSequence& buf);
 
     /// Synchronously flush the data to the supplied SyncWriteStream
     /**
@@ -134,13 +96,8 @@
      * If there is no error, the buffer is cleared.
      */
     template<typename SyncWriteStream>
- void flush(SyncWriteStream& sws)
- {
- boost::system::error_code ec;
- flush(sws, ec);
- detail::throw_error(ec);
- }
-
+ void flush(SyncWriteStream& sws);
+
     /// Synchronously flush the data via the supplied request
     /**
      * This call uses error_code semantics. ie. ec is set if an error occurs.
@@ -148,24 +105,7 @@
      */
     template<typename SyncWriteStream>
     boost::system::error_code
- flush(SyncWriteStream& sws, boost::system::error_code& ec)
- {
- if (!headers_terminated_)
- {
- std::vector<boost::asio::const_buffer> headers;
- prepare_headers(headers);//, ec);
- common::write(sws, headers, boost::asio::transfer_all(), ec);
- if (ec)
- return ec;
- }
-
- std::size_t bytes_written
- = common::write(sws, buffer_->data(), boost::asio::transfer_all(), ec);
- if (!ec)
- buffer_->consume(bytes_written);
-
- return ec;
- }
+ flush(SyncWriteStream& sws, boost::system::error_code& ec);
 
     /// Synchronously send the data via the supplied request.
     /**
@@ -174,12 +114,7 @@
      * Note: The data in the stream isn't cleared after this call.
      */
     template<typename SyncWriteStream>
- void send(SyncWriteStream& sws)
- {
- boost::system::error_code ec;
- send(sws, ec);
- detail::throw_error(ec);
- }
+ void send(SyncWriteStream& sws);
 
     /// Synchronously send the data via the supplied request.
     /**
@@ -189,37 +124,11 @@
      */
     template<typename SyncWriteStream>
     boost::system::error_code
- send(SyncWriteStream& sws, boost::system::error_code& ec)
- {
- if (!headers_terminated_)
- {
- /* Not sure if streambuf allows this
- *
- // We want to be able to keep adding to a response, calling send() on
- // it whenever, without resending the headers. Call resend() if you
- // want to send the whole response again.
- headers_terminated_ = true;
- */
- std::vector<boost::asio::const_buffer> headers;
- prepare_headers(headers);//, ec)
- common::write(sws, headers, boost::asio::transfer_all(), ec);
- }
-
- common::write(sws, buffer_->data(), boost::asio::transfer_all(), ec);
-
- return ec;
- }
+ send(SyncWriteStream& sws, boost::system::error_code& ec);
 
     /// Resend headers + content regardless of value of `headers_terminated_`.
     template<typename SyncWriteStream>
- void resend(SyncWriteStream& sws)
- {
- std::vector<boost::asio::const_buffer> headers;
- prepare_headers(headers);//, ec)
- common::write(sws, headers);
-
- common::write(sws, buffer_->data());
- }
+ void resend(SyncWriteStream& sws);
 
     /// Asynchronously send the data through the supplied request
     /**
@@ -228,105 +137,47 @@
      * this call.
      */
     template<typename AsyncWriteStream, typename Handler>
- void async_send(AsyncWriteStream& aws, Handler handler)
- {
- aws.io_service().post(
- boost::bind(&basic_response<char_type>::do_async_send, aws, handler)
- );
- }
+ void async_send(AsyncWriteStream& aws, Handler handler);
 
     template<typename AsyncWriteStream, typename Handler>
- void do_async_send(AsyncWriteStream& aws, Handler handler)
- {
-
-
- //req.set_status(http_status_);
- /*
- if (!headers_terminated_)
- {
- ostream_<< "Content-type: text/plain\r\n\r\n";
- headers_terminated_ = true;
- }
- */
- common::async_write(aws, rdbuf()->data(), handler);
- }
+ void do_async_send(AsyncWriteStream& aws, Handler handler);
 
     /// Get the buffer associated with the stream
     common::streambuf*
- rdbuf()
- {
- return static_cast<common::streambuf*>(ostream_.rdbuf());
- }
+ rdbuf();
 
     /// Set the status code associated with the response.
     basic_response<char_type>&
- set_status(const http::status_code& num)
- {
- http_status_ = num;
- return *this;
- }
+ set_status(const http::status_code& num);
 
     /// Get the status code associated with the response.
- http::status_code& status()
- {
- return http_status_;
- }
+ common::http::status_code& status();
 
     /// Allow more headers to be added (WARNING: avoid using this).
- void unterminate_headers()
- {
- headers_terminated_ = false;
- }
+ void unterminate_headers();
 
     /// Get the length of the body of the response
- std::size_t content_length()
- {
- return rdbuf()->size();
- }
+ std::size_t content_length();
 
     /// Add a header after appending the CRLF sequence.
     basic_response<char_type>&
- set_header(const string_type& value)
- {
- BOOST_ASSERT(!headers_terminated_);
- headers_.push_back(value + "\r\n");
- return *this;
- }
+ set_header(const string_type& value);
 
     /// Format and add a header given name and value, appending CRLF.
     basic_response<char_type>&
- set_header(string_type const& name, string_type const& value)
- {
- BOOST_ASSERT(!headers_terminated_);
- headers_.push_back(name + ": " + value + "\r\n");
- return *this;
- }
-
- void clear_headers()
- {
- BOOST_ASSERT(!headers_terminated_);
- headers_.clear();
- }
-
- void reset_headers()
- {
- headers_.clear();
- headers_terminated_ = false;
- }
-
- bool headers_terminated() const
- {
- return headers_terminated_;
- }
+ set_header(string_type const& name, string_type const& value);
+
+ void clear_headers();
+
+ void reset_headers();
+
+ bool headers_terminated() const;
 
     // Is this really necessary?
- void end_headers()
- {
- headers_terminated_ = true;
- }
+ void end_headers();
 
     /// Get the ostream containing the response body.
- ostream_type& ostream() { return ostream_; }
+ ostream_type& ostream();
   protected:
     // Vector of all the headers, each followed by a CRLF
     std::vector<string_type> headers_;
@@ -336,43 +187,15 @@
 
     ostream_type ostream_;
 
- http::status_code http_status_;
+ common::http::status_code http_status_;
 
     // True if no more headers can be appended.
     bool headers_terminated_;
 
- //template<typename T>
- //friend response& operator<<(response& resp, const T& t);
-
- //template<typename A, typename B>
- //friend A& operator<<(A& resp, B b);
-
   private:
-
     // Send the response headers and mark that they've been sent.
     template<typename ConstBufferSequence>
- //boost::system::error_code
- void
- prepare_headers(ConstBufferSequence& headers)//, boost::system::error_code& ec)
- {
- BOOST_CGI_ADD_DEFAULT_HEADER
-
- // Terminate the headers.
- if (!headers_terminated_)
- headers_.push_back("\r\n");
-
- //{ Construct a ConstBufferSequence out of the headers we have.
- //std::vector<boost::asio::const_buffer> headers;
- typedef typename std::vector<string_type>::iterator iter;
- for (iter i(headers_.begin()), e(headers_.end()); i != e; ++i)
- {
- headers.push_back(common::buffer(*i));
- }
- //}
-
- headers_terminated_ = true;
- //return ec;
- }
+ void prepare_headers(ConstBufferSequence& headers);
    };
 
    /// Typedefs for typical usage.
@@ -383,58 +206,14 @@
 } // namespace cgi
 
   /// Generic ostream template
- template<typename charT, typename T>
- inline cgi::common::basic_response<charT>&
- operator<< (cgi::common::basic_response<charT>& resp, const T& t)
- {
- resp.ostream()<< t;
- return resp;
- }
-
- /// You can stream a cgi::header into a response.
- /**
- * This is just a more convenient way of doing:
- *
- * ``
- * resp.set_header(header_content)
- * ``
- *
- * [tip
- * If you stream a default-constructed header to a response, it
- * 'terminates' the headers. ie. You can do this if you want to ensure
- * no further headers are added to the response. It has no other side-
- * effects; for instance, it won't write any data to the client.
- * ]
- * /
- template<typename T>
- response& operator<<(response& resp, const ::cgi::basic_header<std::basic_string<T> >& hdr)
- {
- if (hdr.content.empty()) {
- resp.headers_terminated_ = true;
- return resp;
- }else{
- // We shouldn't allow headers to be sent after they're explicitly ended.
- BOOST_ASSERT(!resp.headers_terminated_);
- resp.set_header(hdr.content);
- return resp;
- }
- }*/
-
- template<typename charT>
- inline cgi::common::basic_response<charT>&
- operator<< (cgi::common::basic_response<charT>& resp
- , const ::cgi::common::header& hdr)
- {
- if (hdr.content.empty()) {
- resp.end_headers();
- return resp;
- }else{
- // We shouldn't allow headers to be sent after they're explicitly ended.
- BOOST_ASSERT(!resp.headers_terminated());
- resp.set_header(hdr.content);
- return resp;
- }
- }
+ template<typename CharT, typename T>
+ cgi::common::basic_response<CharT>&
+ operator<< (cgi::common::basic_response<CharT>& resp, const T& t);
+
+ template<typename CharT>
+ cgi::common::basic_response<CharT>&
+ operator<< (cgi::common::basic_response<CharT>& resp
+ , cgi::common::basic_header<CharT> const& hdr);
 
   /// You can stream a cgi::cookie into a response.
   /**
@@ -448,24 +227,17 @@
    * library.
    */
   template<typename charT, typename T>
- inline cgi::common::basic_response<charT>&
- operator<<(cgi::common::basic_response<charT>& resp, cgi::common::basic_cookie<T> ck)
- {
- BOOST_ASSERT(!resp.headers_terminated());
- resp.set_header("Set-cookie", ck.to_string());
- return resp;
- }
+ cgi::common::basic_response<charT>&
+ operator<< (cgi::common::basic_response<charT>&
+ , cgi::common::basic_cookie<T>&);
 
   template<typename charT, typename T>
- inline cgi::common::basic_response<charT>&
- operator<<(cgi::common::basic_response<charT>& resp, cgi::http::status_code status)
- {
- BOOST_ASSERT(!resp.headers_terminated());
- return resp.set_status(status);
- }
-
-#undef BOOST_CGI_ADD_DEFAULT_HEADER
+ cgi::common::basic_response<charT>&
+ operator<< (cgi::common::basic_response<charT>&
+ , cgi::common::http::status_code);
 
 #include "boost/cgi/detail/pop_options.hpp"
 
+#include "boost/cgi/impl/response.ipp"
+
 #endif // CGI_RESPONSE_HPP_INCLUDED__

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/status_type.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/status_type.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/status_type.hpp 2008-05-20 12:08:38 EDT (Tue, 20 May 2008)
@@ -9,18 +9,13 @@
 #ifndef CGI_STATUS_TYPE_HPP_INCLUDED__
 #define CGI_STATUS_TYPE_HPP_INCLUDED__
 
+#include "boost/cgi/common/status_type.hpp"
+
 namespace cgi {
 
- enum status_type
- { null
- , unloaded
- , activated
- , loaded
- , ok = loaded
- , aborted
- , closed
- };
+ using namespace common;
 
 } // namespace cgi
 
 #endif // CGI_STATUS_TYPE_HPP_INCLUDED__
+


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