-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathKHttpResponse.cpp
More file actions
37 lines (31 loc) · 844 Bytes
/
Copy pathKHttpResponse.cpp
File metadata and controls
37 lines (31 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "KHttpResponse.h"
#include "../hpserver/KBuffer.h"
#include <stdio.h>
using namespace kb;
void HttpResponse::appendToBuffer(Buffer *output) const
{
char buf[32];
snprintf(buf, sizeof buf, "HTTP/1.1 %d ", statusCode_);
output->append(buf);
output->append(statusMessage_);
output->append("\r\n");
if (closeConnection_)
{
output->append("Connection: close\r\n");
}
else
{
snprintf(buf, sizeof buf, "Content-Length: %zd\r\n", body_.size());
output->append(buf);
output->append("Connection: Keep-Alive\r\n");
}
for (const auto &header : headers_)
{
output->append(header.first);
output->append(": ");
output->append(header.second);
output->append("\r\n");
}
output->append("\r\n");
output->append(body_);
}