Code cleanup
This commit is contained in:
parent
871d8d67b0
commit
2c07ec4600
25
httplib.h
25
httplib.h
@ -4240,7 +4240,7 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
|
|||||||
std::string boundary;
|
std::string boundary;
|
||||||
if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); }
|
if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); }
|
||||||
|
|
||||||
// Headers
|
// Preapre additional headers
|
||||||
if (close_connection || req.get_header_value("Connection") == "close") {
|
if (close_connection || req.get_header_value("Connection") == "close") {
|
||||||
res.set_header("Connection", "close");
|
res.set_header("Connection", "close");
|
||||||
} else {
|
} else {
|
||||||
@ -4266,7 +4266,10 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
|
|||||||
|
|
||||||
detail::BufferStream bstrm;
|
detail::BufferStream bstrm;
|
||||||
|
|
||||||
// Response line
|
// Response line and headers
|
||||||
|
{
|
||||||
|
detail::BufferStream bstrm;
|
||||||
|
|
||||||
if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status,
|
if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status,
|
||||||
detail::status_message(res.status))) {
|
detail::status_message(res.status))) {
|
||||||
return false;
|
return false;
|
||||||
@ -4277,6 +4280,7 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
|
|||||||
// Flush buffer
|
// Flush buffer
|
||||||
auto &data = bstrm.get_buffer();
|
auto &data = bstrm.get_buffer();
|
||||||
strm.write(data.data(), data.size());
|
strm.write(data.data(), data.size());
|
||||||
|
}
|
||||||
|
|
||||||
// Body
|
// Body
|
||||||
auto ret = true;
|
auto ret = true;
|
||||||
@ -5264,14 +5268,7 @@ inline bool ClientImpl::write_content_with_provider(Stream &strm,
|
|||||||
|
|
||||||
inline bool ClientImpl::write_request(Stream &strm, const Request &req,
|
inline bool ClientImpl::write_request(Stream &strm, const Request &req,
|
||||||
bool close_connection, Error &error) {
|
bool close_connection, Error &error) {
|
||||||
detail::BufferStream bstrm;
|
// Prepare additonal headers
|
||||||
|
|
||||||
// Request line
|
|
||||||
const auto &path = detail::encode_url(req.path);
|
|
||||||
|
|
||||||
bstrm.write_format("%s %s HTTP/1.1\r\n", req.method.c_str(), path.c_str());
|
|
||||||
|
|
||||||
// Additonal headers
|
|
||||||
Headers headers;
|
Headers headers;
|
||||||
if (close_connection) { headers.emplace("Connection", "close"); }
|
if (close_connection) { headers.emplace("Connection", "close"); }
|
||||||
|
|
||||||
@ -5341,6 +5338,13 @@ inline bool ClientImpl::write_request(Stream &strm, const Request &req,
|
|||||||
proxy_bearer_token_auth_token_, true));
|
proxy_bearer_token_auth_token_, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Request line and headers
|
||||||
|
{
|
||||||
|
detail::BufferStream bstrm;
|
||||||
|
|
||||||
|
const auto &path = detail::encode_url(req.path);
|
||||||
|
bstrm.write_format("%s %s HTTP/1.1\r\n", req.method.c_str(), path.c_str());
|
||||||
|
|
||||||
detail::write_headers(bstrm, req, headers);
|
detail::write_headers(bstrm, req, headers);
|
||||||
|
|
||||||
// Flush buffer
|
// Flush buffer
|
||||||
@ -5349,6 +5353,7 @@ inline bool ClientImpl::write_request(Stream &strm, const Request &req,
|
|||||||
error = Error::Write;
|
error = Error::Write;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Body
|
// Body
|
||||||
if (req.body.empty()) {
|
if (req.body.empty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user