-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponse.cpp
More file actions
32 lines (26 loc) · 877 Bytes
/
Copy pathHttpResponse.cpp
File metadata and controls
32 lines (26 loc) · 877 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
#include "HttpResponse.h"
#include <sstream>
HttpResponse::HttpResponse() : statusCode_(200), statusMessage_("OK") {}
void HttpResponse::setStatus(int code, const std::string& message) {
statusCode_ = code;
statusMessage_ = message;
}
void HttpResponse::addHeader(const std::string& key, const std::string& value) {
headers_ += key + ": " + value + "\r\n";
}
void HttpResponse::setBody(const std::string& body) {
body_ = body;
}
void HttpResponse::setConnection(const std::string& value) {
connection_ = value;
}
std::string HttpResponse::toString() const {
std::ostringstream oss;
oss << "HTTP/1.1 " << statusCode_ << " " << statusMessage_ << "\r\n";
oss << headers_;
oss << "Content-Length: " << body_.size() << "\r\n";
oss << "Connection: " << connection_ << "\r\n";
oss << "\r\n";
oss << body_;
return oss.str();
}