Skip to content

Commit 862f614

Browse files
committed
Addendum to #35
This fix improves upon the earlier commit to make the implementation more predictable and semantically consistent with the interface for both the put and post methods.
1 parent a623730 commit 862f614

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,44 @@ namespace boost { namespace network { namespace http {
5555
}
5656

5757
response const post (request request_, string_type const & content_type, string_type const & body_) {
58+
if (!boost::empty(headers(request_)["Content-Type"]))
59+
request_ << remove_header("Content-Type");
60+
5861
request_ << ::boost::network::body(body_)
62+
<< header("Content-Type", content_type)
5963
<< header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
60-
if (!boost::empty(headers(request_)["Content-Type"]))
61-
request_ << header("Content-Type", content_type);
6264
return post(request_);
6365
}
6466

6567
response const post (request const & request_, string_type const & body_) {
66-
return post(request_, "x-application/octet-stream", body_);
68+
string_type content_type = "x-application/octet-stream";
69+
typename headers_range<request>::type content_type_headers =
70+
headers(request_)["Content-Type"];
71+
if (!boost::empty(content_type_headers))
72+
content_type = boost::begin(content_type_headers)->second;
73+
return post(request_, content_type, body_);
6774
}
6875

6976
response const put (request const & request_) {
7077
return pimpl->request_skeleton(request_, "PUT", true);
7178
}
7279

7380
response const put (request const & request_, string_type const & body_) {
74-
return put(request_, "x-application/octet-stream", body_);
81+
string_type content_type = "x-application/octet-stream";
82+
typename headers_range<request>::type content_type_headers =
83+
headers(request_)["Content-Type"];
84+
if (!boost::empty(content_type_headers))
85+
content_type = boost::begin(content_type_headers)->second;
86+
return put(request_, content_type, body_);
7587
}
7688

7789
response const put (request request_, string_type const & content_type, string_type const & body_) {
90+
if (!boost::empty(headers(request_)["Content-Type"]))
91+
request_ << remove_header("Content-Type");
92+
7893
request_ << ::boost::network::body(body_)
94+
<< header("Content-Type", content_type)
7995
<< header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
80-
if (!boost::empty(headers(request_)["Content-Type"]))
81-
request_ << header("Content-Type", content_type);
8296
return put(request_);
8397
}
8498

0 commit comments

Comments
 (0)