return result;
}
+Request Request::parse(const string &str)
+{
+ unsigned lf=str.find('\n');
+ vector<string> parts=split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
+ if(parts.size()<3)
+ throw InvalidParameterValue("Invalid request");
+
+ Request result(parts[0], parts[1]);
+ result.http_version=parse_version(parts[2]);
+
+ lf+=result.parse_headers(str.substr(lf+1));
+
+ result.parse_content(str.substr(lf+1));
+
+ return result;
+}
+
Request Request::from_url(const string &url)
{
- if(RegMatch match=Regex("^http://([a-zA-Z0-9.-]+)(:([0-9]+))?(/[^ #]*)?$").match(url))
+ if(RegMatch match=Regex("^http://([a-zA-Z0-9.-]+(:[0-9]+)?)(/[^ #]*)?$").match(url))
{
string host=match[1].str;
- string port="80";
- if(match[3])
- port=match[3].str;
- string path=match[4].str;
+ string path=match[3].str;
if(path.empty())
path="/";
Request result("GET", path);
- result.set_header("host", host);
- result.set_header("x-port", port);
+ result.set_header("Host", host);
+ result.set_header("Connection", "close");
return result;
}