@@ -5925,8 +5925,8 @@ inline void Server::apply_ranges(const Request &req, Response &res,
5925
5925
res.headers .erase (it);
5926
5926
}
5927
5927
5928
- res.headers . emplace (" Content-Type" ,
5929
- " multipart/byteranges; boundary=" + boundary);
5928
+ res.set_header (" Content-Type" ,
5929
+ " multipart/byteranges; boundary=" + boundary);
5930
5930
}
5931
5931
5932
5932
auto type = detail::encoding_type (req, res);
@@ -6616,32 +6616,32 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req,
6616
6616
// Prepare additional headers
6617
6617
if (close_connection) {
6618
6618
if (!req.has_header (" Connection" )) {
6619
- req.headers . emplace (" Connection" , " close" );
6619
+ req.set_header (" Connection" , " close" );
6620
6620
}
6621
6621
}
6622
6622
6623
6623
if (!req.has_header (" Host" )) {
6624
6624
if (is_ssl ()) {
6625
6625
if (port_ == 443 ) {
6626
- req.headers . emplace (" Host" , host_);
6626
+ req.set_header (" Host" , host_);
6627
6627
} else {
6628
- req.headers . emplace (" Host" , host_and_port_);
6628
+ req.set_header (" Host" , host_and_port_);
6629
6629
}
6630
6630
} else {
6631
6631
if (port_ == 80 ) {
6632
- req.headers . emplace (" Host" , host_);
6632
+ req.set_header (" Host" , host_);
6633
6633
} else {
6634
- req.headers . emplace (" Host" , host_and_port_);
6634
+ req.set_header (" Host" , host_and_port_);
6635
6635
}
6636
6636
}
6637
6637
}
6638
6638
6639
- if (!req.has_header (" Accept" )) { req.headers . emplace (" Accept" , " */*" ); }
6639
+ if (!req.has_header (" Accept" )) { req.set_header (" Accept" , " */*" ); }
6640
6640
6641
6641
#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
6642
6642
if (!req.has_header (" User-Agent" )) {
6643
6643
auto agent = std::string (" cpp-httplib/" ) + CPPHTTPLIB_VERSION;
6644
- req.headers . emplace (" User-Agent" , agent);
6644
+ req.set_header (" User-Agent" , agent);
6645
6645
}
6646
6646
#endif
6647
6647
@@ -6650,23 +6650,23 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req,
6650
6650
if (!req.is_chunked_content_provider_ ) {
6651
6651
if (!req.has_header (" Content-Length" )) {
6652
6652
auto length = std::to_string (req.content_length_ );
6653
- req.headers . emplace (" Content-Length" , length);
6653
+ req.set_header (" Content-Length" , length);
6654
6654
}
6655
6655
}
6656
6656
} else {
6657
6657
if (req.method == " POST" || req.method == " PUT" ||
6658
6658
req.method == " PATCH" ) {
6659
- req.headers . emplace (" Content-Length" , " 0" );
6659
+ req.set_header (" Content-Length" , " 0" );
6660
6660
}
6661
6661
}
6662
6662
} else {
6663
6663
if (!req.has_header (" Content-Type" )) {
6664
- req.headers . emplace (" Content-Type" , " text/plain" );
6664
+ req.set_header (" Content-Type" , " text/plain" );
6665
6665
}
6666
6666
6667
6667
if (!req.has_header (" Content-Length" )) {
6668
6668
auto length = std::to_string (req.body .size ());
6669
- req.headers . emplace (" Content-Length" , length);
6669
+ req.set_header (" Content-Length" , length);
6670
6670
}
6671
6671
}
6672
6672
@@ -6734,12 +6734,10 @@ inline std::unique_ptr<Response> ClientImpl::send_with_content_provider(
6734
6734
ContentProvider content_provider,
6735
6735
ContentProviderWithoutLength content_provider_without_length,
6736
6736
const std::string &content_type, Error &error) {
6737
- if (!content_type.empty ()) {
6738
- req.headers .emplace (" Content-Type" , content_type);
6739
- }
6737
+ if (!content_type.empty ()) { req.set_header (" Content-Type" , content_type); }
6740
6738
6741
6739
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
6742
- if (compress_) { req.headers . emplace (" Content-Encoding" , " gzip" ); }
6740
+ if (compress_) { req.set_header (" Content-Encoding" , " gzip" ); }
6743
6741
#endif
6744
6742
6745
6743
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
@@ -6800,7 +6798,7 @@ inline std::unique_ptr<Response> ClientImpl::send_with_content_provider(
6800
6798
req.content_provider_ = detail::ContentProviderAdapter (
6801
6799
std::move (content_provider_without_length));
6802
6800
req.is_chunked_content_provider_ = true ;
6803
- req.headers . emplace (" Transfer-Encoding" , " chunked" );
6801
+ req.set_header (" Transfer-Encoding" , " chunked" );
6804
6802
} else {
6805
6803
req.body .assign (body, content_length);
6806
6804
;
@@ -7423,9 +7421,7 @@ inline Result ClientImpl::Delete(const std::string &path,
7423
7421
req.headers = headers;
7424
7422
req.path = path;
7425
7423
7426
- if (!content_type.empty ()) {
7427
- req.headers .emplace (" Content-Type" , content_type);
7428
- }
7424
+ if (!content_type.empty ()) { req.set_header (" Content-Type" , content_type); }
7429
7425
req.body .assign (body, content_length);
7430
7426
7431
7427
return send_ (std::move (req));
0 commit comments