3 This file is part of libmsphttp
4 Copyright © 2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
8 #include <msp/strings/formatter.h>
9 #include <msp/strings/utils.h>
17 Response::Response(Status s):
21 string Response::str() const
23 string result=format("%s %d %s\r\n", version_str(http_version), int(status), status);
29 Response Response::parse(const string &str)
33 unsigned lf=str.find('\n');
34 vector<string> parts=split(str.substr(0, lf), ' ');
36 throw InvalidParameterValue("Invalid response");
38 result.http_version=parse_version(parts[0]);
39 result.status=static_cast<Status>(lexical_cast<unsigned>(parts[1]));
44 lf=str.find('\n', start);
46 throw InvalidParameterValue("Incomplete response");
47 if(lf==start || (str[start]=='\r' && lf==start+1))
50 unsigned colon=str.find(':', start);
52 throw InvalidParameterValue("No colon in header");
54 result.set_header(str.substr(start, colon-start), strip(str.substr(colon+1, lf-colon-1)));
59 result.parse_content(str.substr(lf+1));