17
17
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_RESPONSE_RESPONSE_IPP
18
18
#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_RESPONSE_RESPONSE_IPP
19
19
20
- #include < string>
21
- #include < vector>
22
20
#include < boost/asio.hpp>
23
21
#include < boost/lexical_cast.hpp>
22
+ #include < boost/network/traits/string.hpp>
23
+ #include < boost/network/traits/vector.hpp>
24
24
#include < boost/network/protocol/http/header.hpp>
25
25
26
26
namespace boost {namespace network {namespace http {
@@ -53,10 +53,12 @@ namespace boost { namespace network { namespace http {
53
53
} status;
54
54
55
55
// / 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;
57
58
58
59
// / 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;
60
62
61
63
// / Convert the reply into a vector of buffers. The buffers do not own the
62
64
// / underlying memory blocks, therefore the reply object must remain valid and
@@ -83,21 +85,26 @@ namespace boost { namespace network { namespace http {
83
85
84
86
// / Get a stock reply.
85
87
static 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) {
86
93
using boost::lexical_cast;
87
94
basic_response<tags::http_server> rep;
88
95
rep.status = status;
89
- rep.content =to_string (status) ;
96
+ rep.content =content ;
90
97
rep.headers .resize (2 );
91
98
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 ());
93
100
rep.headers [1 ].name =" Content-Type" ;
94
101
rep.headers [1 ].value =" text/html" ;
95
102
return rep;
96
103
}
97
104
98
105
private:
99
106
100
- static std::string to_string (status_type status) {
107
+ static string_type to_string (status_type status) {
101
108
static const char ok[] =" " ;
102
109
static const char created[] =
103
110
" <html>"
@@ -230,41 +237,41 @@ namespace boost { namespace network { namespace http {
230
237
231
238
boost::asio::const_bufferto_buffer (status_type status) {
232
239
using boost::asio::buffer;
233
- static const std::string ok =
240
+ static const string_type ok =
234
241
" HTTP/1.0 200 OK\r\n " ;
235
- static const std::string created =
242
+ static const string_type created =
236
243
" HTTP/1.0 201 Created\r\n " ;
237
- static const std::string accepted =
244
+ static const string_type accepted =
238
245
" HTTP/1.0 202 Accepted\r\n " ;
239
- static const std::string no_content =
246
+ static const string_type no_content =
240
247
" HTTP/1.0 204 No Content\r\n " ;
241
- static const std::string multiple_choices =
248
+ static const string_type multiple_choices =
242
249
" HTTP/1.0 300 Multiple Choices\r\n " ;
243
- static const std::string moved_permanently =
250
+ static const string_type moved_permanently =
244
251
" HTTP/1.0 301 Moved Permanently\r\n " ;
245
- static const std::string moved_temporarily =
252
+ static const string_type moved_temporarily =
246
253
" HTTP/1.0 302 Moved Temporarily\r\n " ;
247
- static const std::string not_modified =
254
+ static const string_type not_modified =
248
255
" HTTP/1.0 304 Not Modified\r\n " ;
249
- static const std::string bad_request =
256
+ static const string_type bad_request =
250
257
" HTTP/1.0 400 Bad Request\r\n " ;
251
- static const std::string unauthorized =
258
+ static const string_type unauthorized =
252
259
" HTTP/1.0 401 Unauthorized\r\n " ;
253
- static const std::string forbidden =
260
+ static const string_type forbidden =
254
261
" HTTP/1.0 403 Forbidden\r\n " ;
255
- static const std::string not_found =
262
+ static const string_type not_found =
256
263
" HTTP/1.0 404 Not Found\r\n " ;
257
- static const std::string not_supported =
264
+ static const string_type not_supported =
258
265
" HTTP/1.0 405 Method Not Supported\r\n " ;
259
- static const std::string not_acceptable =
266
+ static const string_type not_acceptable =
260
267
" 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 =
262
269
" HTTP/1.0 500 Internal Server Error\r\n " ;
263
- static const std::string not_implemented =
270
+ static const string_type not_implemented =
264
271
" HTTP/1.0 501 Not Implemented\r\n " ;
265
- static const std::string bad_gateway =
272
+ static const string_type bad_gateway =
266
273
" HTTP/1.0 502 Bad Gateway\r\n " ;
267
- static const std::string service_unavailable =
274
+ static const string_type service_unavailable =
268
275
" HTTP/1.0 503 Service Unavailable\r\n " ;
269
276
270
277
switch (status) {