2 #include <msp/strings/format.h>
3 #include <msp/strings/utils.h>
10 Response::Response(Status s):
14 string Response::str() const
16 string result = format("%s %d %s\r\n", version_str(http_version), static_cast<int>(status), status);
17 result += str_common();
22 Response Response::parse(const string &str)
26 string::size_type lf = str.find('\n');
28 throw invalid_argument("Response::parse");
29 vector<string> parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
31 throw invalid_argument("Response::parse");
33 result.http_version = parse_version(parts[0]);
34 result.status = static_cast<Status>(lexical_cast<unsigned>(parts[1]));
36 lf += result.parse_headers(str.substr(lf+1));
38 result.parse_content(str.substr(lf+1));