구현 | 응답 보내기
Response 객체의 응답 메시지화
std::string
Response::getString() const
{
std::string message;
std::map<std::string, std::string>::const_iterator it = this->m_headers.begin();
message = m_protocol + " " + ft::to_string(m_status_code) + " " + m_status_description + "\r\n";
for (; it != this->m_headers.end(); ++it)
message += it->first + ": " + it->second + "\r\n";
if (m_connection_type == CLOSE || m_status_code < 200 || m_status_code > 299)
message += "Connection: close\r\n";
else
message += "Connection: Keep-Alive\r\n";
if (m_transfer_type == CHUNKED) {
message += "Transfer-Encoding: chunked\r\n\r\n";
int size = this->m_content.size();
int count;
std::string data = m_content;
int added = 0;
while (size > 0)
{
if (size > BUFFER_SIZE)
count = BUFFER_SIZE;
else
count = size;
message += ft::itos(ft::to_string(count), 10, 16) + "\r\n";
message += data.substr(added, count) + "\r\n";
size -= count;
added += count;
}
data.clear();
message += "0\r\n\r\n";
}
else
{
message += "\r\n";
message += this->m_content;
}
return (message);
}
응답 전송하기
Last updated
Was this helpful?