Skip to content

Commit 2c07ec4

Browse files
committed
Code cleanup
1 parent 871d8d6 commit 2c07ec4

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

httplib.h

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,7 +4240,7 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
42404240
std::string boundary;
42414241
if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); }
42424242

4243-
// Headers
4243+
// Preapre additional headers
42444244
if (close_connection || req.get_header_value("Connection") == "close") {
42454245
res.set_header("Connection", "close");
42464246
} else {
@@ -4266,17 +4266,21 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
42664266

42674267
detail::BufferStream bstrm;
42684268

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+
}
42744277

4275-
if (!detail::write_headers(bstrm, res, Headers())) { return false; }
4278+
if (!detail::write_headers(bstrm, res, Headers())) { return false; }
42764279

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+
}
42804284

42814285
// Body
42824286
auto ret = true;
@@ -5264,14 +5268,7 @@ inline bool ClientImpl::write_content_with_provider(Stream &strm,
52645268

52655269
inline bool ClientImpl::write_request(Stream &strm, const Request &req,
52665270
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
52755272
Headers headers;
52765273
if (close_connection) { headers.emplace("Connection", "close"); }
52775274

@@ -5341,13 +5338,21 @@ inline bool ClientImpl::write_request(Stream &strm, const Request &req,
53415338
proxy_bearer_token_auth_token_, true));
53425339
}
53435340

5344-
detail::write_headers(bstrm, req, headers);
5341+
// Request line and headers
5342+
{
5343+
detail::BufferStream bstrm;
53455344

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+
}
53515356
}
53525357

53535358
// Body

0 commit comments

Comments
 (0)