11
11
#include < boost/network/protocol/http/message/header_concept.hpp>
12
12
#include < boost/network/constants.hpp>
13
13
#include < boost/concept_check.hpp>
14
+ #include < boost/range/algorithm/copy.hpp>
14
15
15
16
namespace boost { namespace network { namespace http {
16
17
17
18
template <class Tag >
18
- struct linearize {
19
+ struct linearize_header {
19
20
typedef typename string<Tag>::type string_type;
20
21
21
22
template <class Arguments >
@@ -40,11 +41,97 @@ namespace boost { namespace network { namespace http {
40
41
return header_line.str ();
41
42
}
42
43
};
44
+
45
+ template <class Tag , class OutputIterator >
46
+ OutputIterator linearize (
47
+ basic_request<Tag> const & request,
48
+ typename string<Tag>::type const & method,
49
+ unsigned version_major,
50
+ unsigned version_minor,
51
+ OutputIterator oi
52
+ )
53
+ {
54
+ typedef constants<Tag> consts;
55
+ typedef typename string<Tag>::type string_type;
56
+ static string_type
57
+ http_slash = consts::http_slash ()
58
+ , accept = consts::accept ()
59
+ , accept_mime = consts::default_accept_mime ()
60
+ , accept_encoding = consts::accept_encoding ()
61
+ , default_accept_encoding = consts::default_accept_encoding ()
62
+ , crlf = consts::crlf ()
63
+ , host = consts::host ()
64
+ , connection = consts::connection ()
65
+ , close = consts::close ()
66
+ ;
67
+ boost::copy (method, oi);
68
+ *oi = consts::space_char ();
69
+ if (request.path ().empty () || request.path ()[0 ] != consts::slash_char ())
70
+ *oi = consts::slash_char ();
71
+ boost::copy (request.path (), oi);
72
+ if (!request.query ().empty ()) {
73
+ *oi = consts::question_mark_char ();
74
+ boost::copy (request.query (), oi);
75
+ }
76
+ if (!request.anchor ().empty ()) {
77
+ *oi = consts::hash_char ();
78
+ boost::copy (request.anchor (), oi);
79
+ }
80
+ *oi = consts::space_char ();
81
+ boost::copy (http_slash, oi);
82
+ string_type version_major_str = boost::lexical_cast<string_type>(version_major),
83
+ version_minor_str = boost::lexical_cast<string_type>(version_minor);
84
+ boost::copy (version_major_str, oi);
85
+ *oi = consts::dot_char ();
86
+ boost::copy (version_minor_str, oi);
87
+ boost::copy (crlf, oi);
88
+ boost::copy (host, oi);
89
+ *oi = consts::colon_char ();
90
+ *oi = consts::space_char ();
91
+ boost::copy (request.host (), oi);
92
+ boost::copy (host, oi);
93
+ boost::copy (accept, oi);
94
+ *oi = consts::colon_char ();
95
+ *oi = consts::space_char ();
96
+ boost::copy (accept_mime, oi);
97
+ boost::copy (crlf, oi);
98
+ if (version_major == 1u && version_minor == 1u ) {
99
+ boost::copy (accept_encoding, oi);
100
+ *oi = consts::colon_char ();
101
+ *oi = consts::space_char ();
102
+ boost::copy (default_accept_encoding, oi);
103
+ }
104
+ typedef typename headers_range<basic_request<Tag> >::type headers_range;
105
+ typedef typename range_iterator<headers_range>::type headers_iterator;
106
+ headers_range request_headers = headers (request);
107
+ headers_iterator iterator = boost::begin (request_headers),
108
+ end = boost::end (request_headers);
109
+ for (; iterator != end; ++iterator) {
110
+ string_type header_name = name (*iterator),
111
+ header_value = value (*iterator);
112
+ boost::copy (header_name, oi);
113
+ *oi = consts::colon_char ();
114
+ *oi = consts::space_char ();
115
+ boost::copy (header_value, oi);
116
+ boost::copy (crlf, oi);
117
+ }
118
+ if (!connection_keepalive<Tag>::value) {
119
+ boost::copy (connection, oi);
120
+ *oi = consts::colon_char ();
121
+ *oi = consts::space_char ();
122
+ boost::copy (close, oi);
123
+ boost::copy (crlf, oi);
124
+ }
125
+ boost::copy (crlf, oi);
126
+ typename body_range<basic_request<Tag> >::type body_data = body (request).range ();
127
+ return boost::copy (body_data, oi);
128
+ }
43
129
44
- } /* linearize */
130
+ } /* http */
45
131
46
132
} /* net */
47
133
48
134
} /* boost */
49
135
50
136
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028 */
137
+
0 commit comments