Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4389238

Browse files
committed
Fixes#41 : Use Boost.Parameter in HTTP Client API member functions.
1 parentead53cf commit4389238

File tree

2 files changed

+70
-48
lines changed

2 files changed

+70
-48
lines changed

‎boost/network/protocol/http/client/facade.hpp‎

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -41,62 +41,80 @@ namespace boost { namespace network { namespace http {
4141
>::type());
4242
}
4343

44-
responseconsthead (requestconst & request_) {
45-
return pimpl->request_skeleton(request_,"HEAD",false);
44+
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), head, tag, (required (request,(requestconst &)))) {
45+
return pimpl->request_skeleton(request,"HEAD",false);
4646
}
4747

48-
responseconstget(requestconst & request_) {
49-
return pimpl->request_skeleton(request_,"GET",true);
48+
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), get, tag, (required (request,(requestconst &)))) {
49+
return pimpl->request_skeleton(request,"GET",true);
5050
}
5151

52-
responseconstpost (requestconst & request_) {
53-
return pimpl->request_skeleton(request_,"POST",true);
52+
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst),post, tag,
53+
(required
54+
(request,(request))// yes sir, we make a copy of the original request.
55+
)
56+
(optional
57+
(body,(string_typeconst &),string_type())
58+
(content_type,(string_typeconst &),string_type())
59+
)
60+
) {
61+
if (body !=string_type()) {
62+
request <<remove_header("Content-Length")
63+
<<header("Content-Length", boost::lexical_cast<string_type>(body.size()))
64+
<<boost::network::body(body);
65+
}
66+
typename headers_range<basic_request<Tag> >::type content_type_headers =
67+
headers(request)["Content-Type"];
68+
if (content_type !=string_type()) {
69+
if (!boost::empty(content_type_headers))
70+
request <<remove_header("Content-Type");
71+
request <<header("Content-Type", content_type);
72+
}else {
73+
if (boost::empty(content_type_headers)) {
74+
typedeftypename char_<Tag>::type char_type;
75+
static char_type content_type[] ="x-application/octet-stream";
76+
request <<header("Content-Type", content_type);
77+
}
78+
}
79+
return pimpl->request_skeleton(request,"POST",true);
5480
}
5581

56-
responseconstpost (request request_, string_typeconst & content_type, string_typeconst & body_) {
57-
if (!boost::empty(headers(request_)["Content-Type"]))
58-
request_ <<remove_header("Content-Type");
59-
60-
request_ << ::boost::network::body(body_)
61-
<<header("Content-Type", content_type)
62-
<<header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
63-
returnpost(request_);
64-
}
65-
66-
responseconstpost (requestconst & request_, string_typeconst & body_) {
67-
string_type content_type ="x-application/octet-stream";
68-
typename headers_range<request>::type content_type_headers =
69-
headers(request_)["Content-Type"];
70-
if (!boost::empty(content_type_headers))
71-
content_type =boost::begin(content_type_headers)->second;
72-
returnpost(request_, content_type, body_);
73-
}
74-
75-
responseconstput (requestconst & request_) {
76-
return pimpl->request_skeleton(request_,"PUT",true);
77-
}
78-
79-
responseconstput (requestconst & request_, string_typeconst & body_) {
80-
string_type content_type ="x-application/octet-stream";
81-
typename headers_range<request>::type content_type_headers =
82-
headers(request_)["Content-Type"];
83-
if (!boost::empty(content_type_headers))
84-
content_type =boost::begin(content_type_headers)->second;
85-
returnput(request_, content_type, body_);
86-
}
87-
88-
responseconstput (request request_, string_typeconst & content_type, string_typeconst & body_) {
89-
if (!boost::empty(headers(request_)["Content-Type"]))
90-
request_ <<remove_header("Content-Type");
91-
92-
request_ << ::boost::network::body(body_)
93-
<<header("Content-Type", content_type)
94-
<<header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
95-
returnput(request_);
82+
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), put , tag,
83+
(required
84+
(request,(request))// yes sir, we make a copy of the original request.
85+
)
86+
(optional
87+
(body,(string_typeconst &),string_type())
88+
(content_type,(string_typeconst &),string_type())
89+
)
90+
) {
91+
if (body !=string_type()) {
92+
request <<remove_header("Content-Length")
93+
<<header("Content-Length", boost::lexical_cast<string_type>(body.size()))
94+
<<boost::network::body(body);
95+
}
96+
typename headers_range<basic_request<Tag> >::type content_type_headers =
97+
headers(request)["Content-Type"];
98+
if (content_type !=string_type()) {
99+
if (!boost::empty(content_type_headers))
100+
request <<remove_header("Content-Type");
101+
request <<header("Content-Type", content_type);
102+
}else {
103+
if (boost::empty(content_type_headers)) {
104+
typedeftypename char_<Tag>::type char_type;
105+
static char_type content_type[] ="x-application/octet-stream";
106+
request <<header("Content-Type", content_type);
107+
}
108+
}
109+
return pimpl->request_skeleton(request,"PUT",true);
96110
}
97111

98-
responseconstdelete_ (requestconst & request_) {
99-
return pimpl->request_skeleton(request_,"DELETE",true);
112+
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), delete_, tag,
113+
(required
114+
(request,(requestconst &))
115+
)
116+
) {
117+
return pimpl->request_skeleton(request,"DELETE",true);
100118
}
101119

102120
voidclear_resolved_cache() {

‎boost/network/protocol/http/client/parameters.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ namespace boost { namespace network { namespace http {
1515
BOOST_PARAMETER_NAME(openssl_certificate)
1616
BOOST_PARAMETER_NAME(openssl_verify_path)
1717

18+
BOOST_PARAMETER_NAME(request)
19+
BOOST_PARAMETER_NAME(body)
20+
BOOST_PARAMETER_NAME(content_type)
21+
1822
}/* http*/
1923

2024
}/* network*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp