Skip to content

Commit 30de417

Browse files
committed
Merge branch 'master' of git://github.com/mikhailberis/cpp-netlib
2 parents d7254c3 + 190cfe1 commit 30de417

File tree

16 files changed

+213
-106
lines changed

16 files changed

+213
-106
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ if (Boost_FOUND)
1313
endif()
1414
enable_testing()
1515
add_subdirectory(libs/network/test)
16+
add_subdirectory(libs/mime/test)
17+

Jamroot

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ use-project /boost : $(BOOST_ROOT) ;
1212

1313
using testing ;
1414

15-
build-project libs/network/test ;
15+
build-project libs/network/test ;
16+
build-project libs/mime/test ;
17+

boost/network/detail/wrapper_base.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ namespace boost { namespace network { namespace detail {
1111

1212
template <class Tag>
1313
struct wrapper_base {
14-
typedef Tag tag;
15-
explicit wrapper_base(basic_message<tag> & message_)
14+
explicit wrapper_base(basic_message<Tag> & message_)
1615
: _message(message_)
17-
{ };
16+
{};
1817

1918
protected:
20-
virtual ~wrapper_base()
21-
{ }; // for extending only
19+
~wrapper_base() {}; // for extending only
2220

23-
mutable basic_message<tag> & _message;
21+
basic_message<Tag> & _message;
2422
};
2523

24+
template <class Tag>
25+
struct wrapper_base_const {
26+
explicit wrapper_base_const(basic_message<Tag> const & message_)
27+
: _message(message_)
28+
{}
29+
30+
protected:
31+
~wrapper_base_const() {}; // for extending only
32+
33+
basic_message<Tag> const & _message;
34+
};
35+
36+
2637
} // namespace detail
2738

2839
} // namespace network

boost/network/message.hpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,49 +44,65 @@ namespace boost { namespace network {
4444

4545
typedef Tag tag;
4646

47-
typedef typename headers_container<tag>::type headers_container_type;
48-
typedef typename string<tag>::type string_type;
47+
typedef typename headers_container<Tag>::type headers_container_type;
48+
typedef typename string<Tag>::type string_type;
4949

5050
basic_message()
5151
: _headers(), _body(), _source(), _destination()
52-
{ };
52+
{ }
5353

5454
basic_message(const basic_message & other)
5555
: _headers(other._headers), _body(other._body), _source(other._source), _destination(other._destination)
56-
{ };
56+
{ }
5757

58-
basic_message & operator=(basic_message<tag> rhs) {
58+
basic_message & operator=(basic_message<Tag> rhs) {
5959
rhs.swap(*this);
6060
return *this;
61-
};
61+
}
6262

63-
void swap(basic_message<tag> & other) {
63+
void swap(basic_message<Tag> & other) {
6464
other._headers.swap(_headers);
6565
other._body.swap(_body);
6666
other._source.swap(_source);
6767
other._destination.swap(_destination);
68-
};
68+
}
6969

7070
headers_container_type & headers() {
7171
return _headers;
72-
};
72+
}
73+
74+
headers_container_type headers() const {
75+
return _headers;
76+
}
7377

7478
string_type & body() {
7579
return _body;
76-
};
80+
}
81+
82+
string_type body() const {
83+
return _body;
84+
}
7785

7886
string_type & source() {
7987
return _source;
80-
};
88+
}
89+
90+
string_type source() const {
91+
return _source;
92+
}
8193

8294
string_type & destination() {
8395
return _destination;
84-
};
96+
}
97+
98+
string_type destination() const {
99+
return _destination;
100+
}
85101

86102
private:
87103

88-
friend struct detail::directive_base<tag> ;
89-
friend struct detail::wrapper_base<tag> ;
104+
friend struct detail::directive_base<Tag> ;
105+
friend struct detail::wrapper_base<Tag> ;
90106

91107
headers_container_type _headers;
92108
string_type _body;

boost/network/message/message_concept.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ struct Message
2727
M message_;
2828
swap(message, message_);
2929

30-
headers_container_type &headers_ = message.headers();
31-
string_type &body_ = message.body();
32-
string_type &source_ = message.source();
33-
string_type &destination_ = message.destination();
30+
headers_container_type headers_ = headers(message);
31+
string_type body_ = body(message);
32+
string_type source_ = source(message);
33+
string_type destination_ = destination(message);
34+
35+
message << source(string_type())
36+
<< destination(string_type())
37+
<< header(string_type(), string_type())
38+
<< body(string_type());
3439

3540
(void)headers_;
3641
(void)body_;

boost/network/message/wrappers/body.hpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,32 @@ namespace boost { namespace network {
1616
namespace impl {
1717
template <class Tag>
1818
struct body_wrapper : public detail::wrapper_base<Tag> {
19-
typedef Tag tag;
20-
typedef basic_message<tag> message_type;
19+
typedef basic_message<Tag> message_type;
2120
typedef typename string<Tag>::type string_type;
2221

23-
explicit body_wrapper(basic_message<tag> & message_)
24-
: detail::wrapper_base<tag>(message_)
22+
explicit body_wrapper(basic_message<Tag> & message_)
23+
: detail::wrapper_base<Tag>(message_)
2524
{ };
2625

2726
operator string_type () const {
2827
return string_type(detail::wrapper_base<Tag>::_message.body());
2928
};
3029
};
30+
31+
template <class Tag>
32+
struct body_wrapper_const : public detail::wrapper_base_const<Tag> {
33+
typedef basic_message<Tag> message_type;
34+
typedef typename string<Tag>::type string_type;
35+
36+
explicit body_wrapper_const(basic_message<Tag> const & message_)
37+
: detail::wrapper_base_const<Tag>(message_)
38+
{};
39+
40+
operator string_type () const {
41+
return string_type(detail::wrapper_base_const<Tag>::_message.body());
42+
}
43+
};
44+
3145
} // namespace impl
3246

3347
template <class Tag>
@@ -36,6 +50,12 @@ namespace boost { namespace network {
3650
return impl::body_wrapper<Tag>(message_);
3751
}
3852

53+
template <class Tag>
54+
inline typename string<Tag>::type
55+
body(basic_message<Tag> const & message_) {
56+
return impl::body_wrapper_const<Tag>(message_);
57+
}
58+
3959
} // namespace network
4060

4161
} // namespace boost

boost/network/message/wrappers/headers.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ namespace boost { namespace network {
3434
* headers_range<basic_message<tag> >::type
3535
* Which allows for full range support.
3636
*
37+
* The type is also convertible to a
38+
* headers_container<Tag>::type
39+
* Which copies the headers from the wrapped message.
40+
*
3741
*/
3842
namespace impl {
3943
template <class Tag>
@@ -70,6 +74,10 @@ namespace boost { namespace network {
7074
return make_iterator_range(headers_wrapper<Tag>::_message.headers().begin(), headers_wrapper<Tag>::_message.headers().end());
7175
};
7276

77+
operator headers_container_type () {
78+
return headers_wrapper<Tag>::_message.headers();
79+
}
80+
7381
};
7482
} // namespace impl
7583

boost/network/protocol/http/client.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,11 @@ namespace boost { namespace network { namespace http {
9191
return sync_request_skeleton(request_, "POST", true);
9292
};
9393

94-
response const post (request const & request_, string_type const & content_type, string_type const & body_) {
95-
request request_copy = request_;
96-
request_copy << body(body_)
94+
response const post (request request_, string_type const & content_type, string_type const & body_) {
95+
request_ << body(body_)
9796
<< header("Content-Type", content_type)
9897
<< header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
99-
return post(request_copy);
98+
return post(request_);
10099
};
101100

102101
response const post (request const & request_, string_type const & body_) {
@@ -111,12 +110,11 @@ namespace boost { namespace network { namespace http {
111110
return put(request_, "x-application/octet-stream", body_);
112111
};
113112

114-
response const put (request const & request_, string_type const & content_type, string_type const & body_) {
115-
request request_copy = request_;
116-
request_copy << body(body_)
113+
response const put (request request_, string_type const & content_type, string_type const & body_) {
114+
request_ << body(body_)
117115
<< header("Content-Type", content_type)
118116
<< header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
119-
return put(request_copy);
117+
return put(request_);
120118
};
121119

122120
response const delete_ (request const & request_) {
@@ -137,7 +135,7 @@ namespace boost { namespace network { namespace http {
137135

138136
};
139137

140-
typedef basic_client<tags::http_default_8bit_tcp_resolve, 1, 0> client;
138+
typedef basic_client<tags::http_default_8bit_udp_resolve, 1, 0> client;
141139

142140
} // namespace http
143141

0 commit comments

Comments
 (0)