It would make str[lf-1] invalid. Also ignore the carriage return at the
end of the first line when parsing a response.
Request Request::parse(const string &str)
{
string::size_type lf = str.find('\n');
+ if(lf==0)
+ throw invalid_argument("Request::parse");
vector<string> parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
if(parts.size()<3)
throw invalid_argument("Request::parse");
Response result;
string::size_type lf = str.find('\n');
- vector<string> parts = split(str.substr(0, lf), ' ', 2);
+ if(lf==0)
+ throw invalid_argument("Response::parse");
+ vector<string> parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
if(parts.size()<2)
throw invalid_argument("Response::parse");