1 #include <msp/strings/formatter.h>
2 #include <msp/strings/regex.h>
3 #include <msp/strings/utils.h>
12 Request::Request(const string &m, const string &p):
17 string Request::str() const
19 string result = format("%s %s %s\r\n", method, path, version_str(http_version));
20 result += str_common();
25 Request Request::parse(const string &str)
27 unsigned lf = str.find('\n');
28 vector<string> parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
30 throw invalid_argument("Request::parse");
32 Request result(parts[0], parts[1]);
33 result.http_version = parse_version(parts[2]);
35 lf += result.parse_headers(str.substr(lf+1));
37 result.parse_content(str.substr(lf+1));
42 Request Request::from_url(const string &str)
44 Url url = parse_url(str);
45 if(url.scheme!="http")
46 throw invalid_argument("Request::from_url");
48 string path = url.path;
51 if(!url.query.empty())
57 Request result("GET", path);
58 result.set_header("Host", url.host);
59 result.set_header("Connection", "close");