-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponse.cc
More file actions
28 lines (24 loc) · 779 Bytes
/
HttpResponse.cc
File metadata and controls
28 lines (24 loc) · 779 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
#include "HttpResponse.h"
#include "net/Buffer.h"
void HttpResponse::appendToBuffer(Buffer *output) const {
char buf[32];
snprintf(buf, sizeof buf, "HTTP/1.1 %d ", status_code_);
output->append(buf);
output->append(status_message_);
output->append("\r\n");
if (close_connection_) {
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_);
}