Skip to content

Commit 25745d5

Browse files
committed
Line endings.
1 parent 9a7f1d9 commit 25745d5

File tree

1 file changed

+149
-149
lines changed

1 file changed

+149
-149
lines changed
Lines changed: 149 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,149 @@
1-
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028
2-
#define BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028
3-
4-
// Copyright 2010 Dean Michael Berris.
5-
// Distributed under the Boost Software License, Version 1.0.
6-
// (See accompanying file LICENSE_1_0.txt or copy at
7-
// http://www.boost.org/LICENSE_1_0.txt)
8-
9-
#include <boost/network/traits/string.hpp>
10-
#include <boost/network/protocol/http/message/header/name.hpp>
11-
#include <boost/network/protocol/http/message/header/value.hpp>
12-
#include <boost/network/protocol/http/message/header_concept.hpp>
13-
#include <boost/network/protocol/http/request_concept.hpp>
14-
#include <boost/network/constants.hpp>
15-
#include <boost/concept/requires.hpp>
16-
#include <boost/optional.hpp>
17-
#include <boost/range/algorithm/copy.hpp>
18-
19-
namespace boost { namespace network { namespace http {
20-
21-
template <class Tag>
22-
struct linearize_header {
23-
typedef typename string<Tag>::type string_type;
24-
25-
template <class Arguments>
26-
struct result;
27-
28-
template <class This, class Arg>
29-
struct result<This(Arg)> {
30-
typedef string_type type;
31-
};
32-
33-
template <class ValueType>
34-
BOOST_CONCEPT_REQUIRES(
35-
((Header<ValueType>)),
36-
(string_type)
37-
) operator()(ValueType & header) {
38-
typedef typename ostringstream<Tag>::type output_stream;
39-
typedef constants<Tag> consts;
40-
output_stream header_line;
41-
header_line << name(header)
42-
<< consts::colon() << consts::space()
43-
<< value(header) << consts::crlf();
44-
return header_line.str();
45-
}
46-
};
47-
48-
template <class Request, class OutputIterator>
49-
BOOST_CONCEPT_REQUIRES(
50-
((ClientRequest<Request>)),
51-
(OutputIterator)
52-
) linearize(
53-
Request const & request,
54-
typename Request::string_type const & method,
55-
unsigned version_major,
56-
unsigned version_minor,
57-
OutputIterator oi
58-
)
59-
{
60-
typedef typename Request::tag Tag;
61-
typedef constants<Tag> consts;
62-
typedef typename string<Tag>::type string_type;
63-
static string_type
64-
http_slash = consts::http_slash()
65-
, accept = consts::accept()
66-
, accept_mime = consts::default_accept_mime()
67-
, accept_encoding = consts::accept_encoding()
68-
, default_accept_encoding = consts::default_accept_encoding()
69-
, crlf = consts::crlf()
70-
, host = consts::host()
71-
, connection = consts::connection()
72-
, close = consts::close()
73-
;
74-
boost::copy(method, oi);
75-
*oi = consts::space_char();
76-
if (request.path().empty() || request.path()[0] != consts::slash_char())
77-
*oi = consts::slash_char();
78-
boost::copy(request.path(), oi);
79-
if (!request.query().empty()) {
80-
*oi = consts::question_mark_char();
81-
boost::copy(request.query(), oi);
82-
}
83-
if (!request.anchor().empty()) {
84-
*oi = consts::hash_char();
85-
boost::copy(request.anchor(), oi);
86-
}
87-
*oi = consts::space_char();
88-
boost::copy(http_slash, oi);
89-
string_type version_major_str = boost::lexical_cast<string_type>(version_major),
90-
version_minor_str = boost::lexical_cast<string_type>(version_minor);
91-
boost::copy(version_major_str, oi);
92-
*oi = consts::dot_char();
93-
boost::copy(version_minor_str, oi);
94-
boost::copy(crlf, oi);
95-
boost::copy(host, oi);
96-
*oi = consts::colon_char();
97-
*oi = consts::space_char();
98-
boost::copy(request.host(), oi);
99-
boost::optional<boost::uint16_t> port_ = port(request);
100-
if (port_) {
101-
string_type port_str = boost::lexical_cast<string_type>(*port_);
102-
*oi = consts::colon_char();
103-
boost::copy(port_str, oi);
104-
}
105-
boost::copy(crlf, oi);
106-
boost::copy(accept, oi);
107-
*oi = consts::colon_char();
108-
*oi = consts::space_char();
109-
boost::copy(accept_mime, oi);
110-
boost::copy(crlf, oi);
111-
if (version_major == 1u && version_minor == 1u) {
112-
boost::copy(accept_encoding, oi);
113-
*oi = consts::colon_char();
114-
*oi = consts::space_char();
115-
boost::copy(default_accept_encoding, oi);
116-
boost::copy(crlf, oi);
117-
}
118-
typedef typename headers_range<Request>::type headers_range;
119-
typedef typename range_value<headers_range>::type headers_value;
120-
BOOST_FOREACH(const headers_value &header, headers(request))
121-
{
122-
string_type header_name = name(header),
123-
header_value = value(header);
124-
boost::copy(header_name, oi);
125-
*oi = consts::colon_char();
126-
*oi = consts::space_char();
127-
boost::copy(header_value, oi);
128-
boost::copy(crlf, oi);
129-
}
130-
if (!connection_keepalive<Tag>::value) {
131-
boost::copy(connection, oi);
132-
*oi = consts::colon_char();
133-
*oi = consts::space_char();
134-
boost::copy(close, oi);
135-
boost::copy(crlf, oi);
136-
}
137-
boost::copy(crlf, oi);
138-
typename body_range<Request>::type body_data = body(request).range();
139-
return boost::copy(body_data, oi);
140-
}
141-
142-
} /* http */
143-
144-
} /* net */
145-
146-
} /* boost */
147-
148-
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028 */
149-
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028
3+
4+
// Copyright 2010 Dean Michael Berris.
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <boost/network/traits/string.hpp>
10+
#include <boost/network/protocol/http/message/header/name.hpp>
11+
#include <boost/network/protocol/http/message/header/value.hpp>
12+
#include <boost/network/protocol/http/message/header_concept.hpp>
13+
#include <boost/network/protocol/http/request_concept.hpp>
14+
#include <boost/network/constants.hpp>
15+
#include <boost/concept/requires.hpp>
16+
#include <boost/optional.hpp>
17+
#include <boost/range/algorithm/copy.hpp>
18+
19+
namespace boost { namespace network { namespace http {
20+
21+
template <class Tag>
22+
struct linearize_header {
23+
typedef typename string<Tag>::type string_type;
24+
25+
template <class Arguments>
26+
struct result;
27+
28+
template <class This, class Arg>
29+
struct result<This(Arg)> {
30+
typedef string_type type;
31+
};
32+
33+
template <class ValueType>
34+
BOOST_CONCEPT_REQUIRES(
35+
((Header<ValueType>)),
36+
(string_type)
37+
) operator()(ValueType & header) {
38+
typedef typename ostringstream<Tag>::type output_stream;
39+
typedef constants<Tag> consts;
40+
output_stream header_line;
41+
header_line << name(header)
42+
<< consts::colon() << consts::space()
43+
<< value(header) << consts::crlf();
44+
return header_line.str();
45+
}
46+
};
47+
48+
template <class Request, class OutputIterator>
49+
BOOST_CONCEPT_REQUIRES(
50+
((ClientRequest<Request>)),
51+
(OutputIterator)
52+
) linearize(
53+
Request const & request,
54+
typename Request::string_type const & method,
55+
unsigned version_major,
56+
unsigned version_minor,
57+
OutputIterator oi
58+
)
59+
{
60+
typedef typename Request::tag Tag;
61+
typedef constants<Tag> consts;
62+
typedef typename string<Tag>::type string_type;
63+
static string_type
64+
http_slash = consts::http_slash()
65+
, accept = consts::accept()
66+
, accept_mime = consts::default_accept_mime()
67+
, accept_encoding = consts::accept_encoding()
68+
, default_accept_encoding = consts::default_accept_encoding()
69+
, crlf = consts::crlf()
70+
, host = consts::host()
71+
, connection = consts::connection()
72+
, close = consts::close()
73+
;
74+
boost::copy(method, oi);
75+
*oi = consts::space_char();
76+
if (request.path().empty() || request.path()[0] != consts::slash_char())
77+
*oi = consts::slash_char();
78+
boost::copy(request.path(), oi);
79+
if (!request.query().empty()) {
80+
*oi = consts::question_mark_char();
81+
boost::copy(request.query(), oi);
82+
}
83+
if (!request.anchor().empty()) {
84+
*oi = consts::hash_char();
85+
boost::copy(request.anchor(), oi);
86+
}
87+
*oi = consts::space_char();
88+
boost::copy(http_slash, oi);
89+
string_type version_major_str = boost::lexical_cast<string_type>(version_major),
90+
version_minor_str = boost::lexical_cast<string_type>(version_minor);
91+
boost::copy(version_major_str, oi);
92+
*oi = consts::dot_char();
93+
boost::copy(version_minor_str, oi);
94+
boost::copy(crlf, oi);
95+
boost::copy(host, oi);
96+
*oi = consts::colon_char();
97+
*oi = consts::space_char();
98+
boost::copy(request.host(), oi);
99+
boost::optional<boost::uint16_t> port_ = port(request);
100+
if (port_) {
101+
string_type port_str = boost::lexical_cast<string_type>(*port_);
102+
*oi = consts::colon_char();
103+
boost::copy(port_str, oi);
104+
}
105+
boost::copy(crlf, oi);
106+
boost::copy(accept, oi);
107+
*oi = consts::colon_char();
108+
*oi = consts::space_char();
109+
boost::copy(accept_mime, oi);
110+
boost::copy(crlf, oi);
111+
if (version_major == 1u && version_minor == 1u) {
112+
boost::copy(accept_encoding, oi);
113+
*oi = consts::colon_char();
114+
*oi = consts::space_char();
115+
boost::copy(default_accept_encoding, oi);
116+
boost::copy(crlf, oi);
117+
}
118+
typedef typename headers_range<Request>::type headers_range;
119+
typedef typename range_value<headers_range>::type headers_value;
120+
BOOST_FOREACH(const headers_value &header, headers(request))
121+
{
122+
string_type header_name = name(header),
123+
header_value = value(header);
124+
boost::copy(header_name, oi);
125+
*oi = consts::colon_char();
126+
*oi = consts::space_char();
127+
boost::copy(header_value, oi);
128+
boost::copy(crlf, oi);
129+
}
130+
if (!connection_keepalive<Tag>::value) {
131+
boost::copy(connection, oi);
132+
*oi = consts::colon_char();
133+
*oi = consts::space_char();
134+
boost::copy(close, oi);
135+
boost::copy(crlf, oi);
136+
}
137+
boost::copy(crlf, oi);
138+
typename body_range<Request>::type body_data = body(request).range();
139+
return boost::copy(body_data, oi);
140+
}
141+
142+
} /* http */
143+
144+
} /* net */
145+
146+
} /* boost */
147+
148+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028 */
149+

0 commit comments

Comments
 (0)