summaryrefslogtreecommitdiff
path: root/src/HttpResponse.cpp
blob: d696e036412c666379d2a0e53c147aa2eb70e7d4 (plain)
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>

static std::string status_code_string(HttpStatusCode status_code)
{
	switch (status_code) {
	case HttpStatusCode::OK:
		return "200 OK";
	}
}

HttpResponse::HttpResponse(HttpStatusCode status_code)
	: m_status_code(status_code)
{
}

void HttpResponse::add_header(const std::string& header, const std::string& value)
{
	m_headers[header] = value;
}

std::string HttpResponse::to_string() const
{
	std::stringstream string_stream;
	string_stream << "HTTP/1.0 " << status_code_string(m_status_code) << "\r\n";
	for (const auto& header : m_headers)
		string_stream << header.first << ": " << header.second << "\r\n";
	string_stream << "\r\n" << m_content;

	return string_stream.str();
}