in include/ylt/standalone/cinatra/coro_http_response.hpp [287:352]
void build_resp_head(std::vector<asio::const_buffer> &buffers) {
bool has_len = false;
bool has_host = false;
check_header(resp_headers_, has_len, has_host);
if (!resp_header_span_.empty()) {
check_header(resp_header_span_, has_len, has_host);
}
if (!has_host) {
buffers.emplace_back(asio::buffer(CINATRA_HOST_SV));
}
if (content_.empty() && !has_set_content_ &&
fmt_type_ != format_type::chunked) {
content_.append(default_status_content(status_));
}
if (fmt_type_ == format_type::chunked) {
buffers.emplace_back(asio::buffer(TRANSFER_ENCODING_SV));
}
else {
if (!cookies_.empty()) {
for (auto &[_, cookie] : cookies_) {
resp_headers_.emplace_back(
resp_header{"Set-Cookie", cookie.to_string()});
}
}
if (!content_.empty()) {
if (!has_len)
handle_content_len(buffers, content_);
}
else if (!content_view_.empty()) {
if (!has_len)
handle_content_len(buffers, content_view_);
}
else {
if (!has_len && boundary_.empty())
buffers.emplace_back(asio::buffer(ZERO_LENGTH_SV));
}
}
if (need_date_) {
buffers.emplace_back(asio::buffer(DATE_SV));
buffers.emplace_back(asio::buffer(get_gmt_time_str()));
buffers.emplace_back(asio::buffer(CRCF));
}
if (keepalive_.has_value()) {
bool keepalive = keepalive_.value();
keepalive ? buffers.emplace_back(asio::buffer(CONN_KEEP_SV))
: buffers.emplace_back(asio::buffer(CONN_CLOSE_SV));
}
if (!content_type_.empty()) {
buffers.emplace_back(asio::buffer(content_type_));
}
append_header(buffers, resp_headers_);
if (!resp_header_span_.empty()) {
append_header(buffers, resp_header_span_);
}
buffers.emplace_back(asio::buffer(CRCF));
}