X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresponse.cpp;h=fe7469d0780d32372f392d80bacf5fbe65be434c;hb=df006bfbbe8e8b49a52296f42894d4a452ed4c90;hp=86d06baf07f42c99097ea3733d0dce6f6d3935e4;hpb=070d56e7b0036ca2e4234eb06dcae83ebfb3df34;p=libs%2Fnet.git diff --git a/source/response.cpp b/source/response.cpp index 86d06ba..fe7469d 100644 --- a/source/response.cpp +++ b/source/response.cpp @@ -20,8 +20,8 @@ Response::Response(Status s): string Response::str() const { - string result=format("%s %d %s\r\n", version_str(http_version), int(status), status); - result+=str_common(); + string result = format("%s %d %s\r\n", version_str(http_version), static_cast(status), status); + result += str_common(); return result; } @@ -30,33 +30,17 @@ Response Response::parse(const string &str) { Response result; - unsigned lf=str.find('\n'); - vector parts=split(str.substr(0, lf), ' '); + unsigned lf = str.find('\n'); + vector parts = split(str.substr(0, lf), ' ', 2); if(parts.size()<2) throw InvalidParameterValue("Invalid response"); - result.http_version=parse_version(parts[0]); - result.status=static_cast(lexical_cast(parts[1])); + result.http_version = parse_version(parts[0]); + result.status = static_cast(lexical_cast(parts[1])); - unsigned start=lf+1; - while(1) - { - lf=str.find('\n', start); - if(lf==string::npos) - throw InvalidParameterValue("Incomplete response"); - if(lf==start || (str[start]=='\r' && lf==start+1)) - break; + lf += result.parse_headers(str.substr(lf+1)); - unsigned colon=str.find(':', start); - if(colon>lf) - throw InvalidParameterValue("No colon in header"); - - result.set_header(str.substr(start, colon-start), strip(str.substr(colon+1, lf-colon-1))); - - start=lf+1; - } - - result.parse_data(str.substr(lf+1)); + result.parse_content(str.substr(lf+1)); return result; }