@@ -4240,7 +4240,7 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
4240
4240
std::string boundary;
4241
4241
if (need_apply_ranges) { apply_ranges (req, res, content_type, boundary); }
4242
4242
4243
- // Headers
4243
+ // Preapre additional headers
4244
4244
if (close_connection || req.get_header_value (" Connection" ) == " close" ) {
4245
4245
res.set_header (" Connection" , " close" );
4246
4246
} else {
@@ -4266,17 +4266,21 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
4266
4266
4267
4267
detail::BufferStream bstrm;
4268
4268
4269
- // Response line
4270
- if (!bstrm.write_format (" HTTP/1.1 %d %s\r\n " , res.status ,
4271
- detail::status_message (res.status ))) {
4272
- return false ;
4273
- }
4269
+ // Response line and headers
4270
+ {
4271
+ detail::BufferStream bstrm;
4272
+
4273
+ if (!bstrm.write_format (" HTTP/1.1 %d %s\r\n " , res.status ,
4274
+ detail::status_message (res.status ))) {
4275
+ return false ;
4276
+ }
4274
4277
4275
- if (!detail::write_headers (bstrm, res, Headers ())) { return false ; }
4278
+ if (!detail::write_headers (bstrm, res, Headers ())) { return false ; }
4276
4279
4277
- // Flush buffer
4278
- auto &data = bstrm.get_buffer ();
4279
- strm.write (data.data (), data.size ());
4280
+ // Flush buffer
4281
+ auto &data = bstrm.get_buffer ();
4282
+ strm.write (data.data (), data.size ());
4283
+ }
4280
4284
4281
4285
// Body
4282
4286
auto ret = true ;
@@ -5264,14 +5268,7 @@ inline bool ClientImpl::write_content_with_provider(Stream &strm,
5264
5268
5265
5269
inline bool ClientImpl::write_request (Stream &strm, const Request &req,
5266
5270
bool close_connection, Error &error) {
5267
- detail::BufferStream bstrm;
5268
-
5269
- // Request line
5270
- const auto &path = detail::encode_url (req.path );
5271
-
5272
- bstrm.write_format (" %s %s HTTP/1.1\r\n " , req.method .c_str (), path.c_str ());
5273
-
5274
- // Additonal headers
5271
+ // Prepare additonal headers
5275
5272
Headers headers;
5276
5273
if (close_connection) { headers.emplace (" Connection" , " close" ); }
5277
5274
@@ -5341,13 +5338,21 @@ inline bool ClientImpl::write_request(Stream &strm, const Request &req,
5341
5338
proxy_bearer_token_auth_token_, true ));
5342
5339
}
5343
5340
5344
- detail::write_headers (bstrm, req, headers);
5341
+ // Request line and headers
5342
+ {
5343
+ detail::BufferStream bstrm;
5345
5344
5346
- // Flush buffer
5347
- auto &data = bstrm.get_buffer ();
5348
- if (!detail::write_data (strm, data.data (), data.size ())) {
5349
- error = Error::Write;
5350
- return false ;
5345
+ const auto &path = detail::encode_url (req.path );
5346
+ bstrm.write_format (" %s %s HTTP/1.1\r\n " , req.method .c_str (), path.c_str ());
5347
+
5348
+ detail::write_headers (bstrm, req, headers);
5349
+
5350
+ // Flush buffer
5351
+ auto &data = bstrm.get_buffer ();
5352
+ if (!detail::write_data (strm, data.data (), data.size ())) {
5353
+ error = Error::Write;
5354
+ return false ;
5355
+ }
5351
5356
}
5352
5357
5353
5358
// Body
0 commit comments