Skip to content

Commit 6659c37

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 8b475fa commit 6659c37

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
@@ -40,30 +40,44 @@ namespace boost { namespace network { namespace http {
4040
}
4141

4242
response const post (request request_, string_type const & content_type, string_type const & body_) {
43+
if (!boost::empty(headers(request_)["Content-Type"]))
44+
request_ << remove_header("Content-Type");
45+
4346
request_ << ::boost::network::body(body_)
47+
<< header("Content-Type", content_type)
4448
<< header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
45-
if (!boost::empty(headers(request_)["Content-Type"]))
46-
request_ << header("Content-Type", content_type);
4749
return post(request_);
4850
}
4951

5052
response const post (request const & request_, string_type const & body_) {
51-
return post(request_, "x-application/octet-stream", body_);
53+
string_type content_type = "x-application/octet-stream";
54+
typename headers_range<request>::type content_type_headers =
55+
headers(request_)["Content-Type"];
56+
if (!boost::empty(content_type_headers))
57+
content_type = boost::begin(content_type_headers)->second;
58+
return post(request_, content_type, body_);
5259
}
5360

5461
response const put (request const & request_) {
5562
return static_cast<Derived*>(this)->request_skeleton(request_, "PUT", true);
5663
}
5764

5865
response const put (request const & request_, string_type const & body_) {
59-
return put(request_, "x-application/octet-stream", body_);
66+
string_type content_type = "x-application/octet-stream";
67+
typename headers_range<request>::type content_type_headers =
68+
headers(request_)["Content-Type"];
69+
if (!boost::empty(content_type_headers))
70+
content_type = boost::begin(content_type_headers)->second;
71+
return put(request_, content_type, body_);
6072
}
6173

6274
response const put (request request_, string_type const & content_type, string_type const & body_) {
75+
if (!boost::empty(headers(request_)["Content-Type"]))
76+
request_ << remove_header("Content-Type");
77+
6378
request_ << ::boost::network::body(body_)
79+
<< header("Content-Type", content_type)
6480
<< header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
65-
if (!boost::empty(headers(request_)["Content-Type"]))
66-
request_ << header("Content-Type", content_type);
6781
return put(request_);
6882
}
6983

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy