1717#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_RESPONSE_RESPONSE_IPP
1818#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_RESPONSE_RESPONSE_IPP
1919
20- #include < string>
21- #include < vector>
2220#include < boost/asio.hpp>
2321#include < boost/lexical_cast.hpp>
22+ #include < boost/network/traits/string.hpp>
23+ #include < boost/network/traits/vector.hpp>
2424#include < boost/network/protocol/http/header.hpp>
2525
2626namespace boost {namespace network {namespace http {
@@ -53,10 +53,12 @@ namespace boost { namespace network { namespace http {
5353 } status;
5454
5555// / The headers to be included in the reply.
56- std::vector<request_header> headers;
56+ typedef vector<tags::http_server>::apply<request_header>::type headers_vector;
57+ headers_vector headers;
5758
5859// / The content to be sent in the reply.
59- std::string content;
60+ typedef string<tags::http_server>::type string_type;
61+ string_type content;
6062
6163// / Convert the reply into a vector of buffers. The buffers do not own the
6264// / underlying memory blocks, therefore the reply object must remain valid and
@@ -83,21 +85,26 @@ namespace boost { namespace network { namespace http {
8385
8486// / Get a stock reply.
8587static basic_response<tags::http_server>stock_reply (status_type status) {
88+ return stock_reply (status,to_string (status));
89+ }
90+
91+ // / Get a stock reply with custom plain text data.
92+ static basic_response<tags::http_server>stock_reply (status_type status, string_type content) {
8693using boost::lexical_cast;
8794 basic_response<tags::http_server> rep;
8895 rep.status = status;
89- rep.content =to_string (status) ;
96+ rep.content =content ;
9097 rep.headers .resize (2 );
9198 rep.headers [0 ].name =" Content-Length" ;
92- rep.headers [0 ].value = lexical_cast<std::string >(rep.content .size ());
99+ rep.headers [0 ].value = lexical_cast<string_type >(rep.content .size ());
93100 rep.headers [1 ].name =" Content-Type" ;
94101 rep.headers [1 ].value =" text/html" ;
95102return rep;
96103 }
97104
98105private:
99106
100- static std::string to_string (status_type status) {
107+ static string_type to_string (status_type status) {
101108static const char ok[] =" " ;
102109static const char created[] =
103110" <html>"
@@ -230,41 +237,41 @@ namespace boost { namespace network { namespace http {
230237
231238 boost::asio::const_bufferto_buffer (status_type status) {
232239using boost::asio::buffer;
233- static const std::string ok =
240+ static const string_type ok =
234241" HTTP/1.0 200 OK\r\n " ;
235- static const std::string created =
242+ static const string_type created =
236243" HTTP/1.0 201 Created\r\n " ;
237- static const std::string accepted =
244+ static const string_type accepted =
238245" HTTP/1.0 202 Accepted\r\n " ;
239- static const std::string no_content =
246+ static const string_type no_content =
240247" HTTP/1.0 204 No Content\r\n " ;
241- static const std::string multiple_choices =
248+ static const string_type multiple_choices =
242249" HTTP/1.0 300 Multiple Choices\r\n " ;
243- static const std::string moved_permanently =
250+ static const string_type moved_permanently =
244251" HTTP/1.0 301 Moved Permanently\r\n " ;
245- static const std::string moved_temporarily =
252+ static const string_type moved_temporarily =
246253" HTTP/1.0 302 Moved Temporarily\r\n " ;
247- static const std::string not_modified =
254+ static const string_type not_modified =
248255" HTTP/1.0 304 Not Modified\r\n " ;
249- static const std::string bad_request =
256+ static const string_type bad_request =
250257" HTTP/1.0 400 Bad Request\r\n " ;
251- static const std::string unauthorized =
258+ static const string_type unauthorized =
252259" HTTP/1.0 401 Unauthorized\r\n " ;
253- static const std::string forbidden =
260+ static const string_type forbidden =
254261" HTTP/1.0 403 Forbidden\r\n " ;
255- static const std::string not_found =
262+ static const string_type not_found =
256263" HTTP/1.0 404 Not Found\r\n " ;
257- static const std::string not_supported =
264+ static const string_type not_supported =
258265" HTTP/1.0 405 Method Not Supported\r\n " ;
259- static const std::string not_acceptable =
266+ static const string_type not_acceptable =
260267" HTTP/1.0 406 Method Not Acceptable\r\n " ;
261- static const std::string internal_server_error =
268+ static const string_type internal_server_error =
262269" HTTP/1.0 500 Internal Server Error\r\n " ;
263- static const std::string not_implemented =
270+ static const string_type not_implemented =
264271" HTTP/1.0 501 Not Implemented\r\n " ;
265- static const std::string bad_gateway =
272+ static const string_type bad_gateway =
266273" HTTP/1.0 502 Bad Gateway\r\n " ;
267- static const std::string service_unavailable =
274+ static const string_type service_unavailable =
268275" HTTP/1.0 503 Service Unavailable\r\n " ;
269276
270277switch (status) {