X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fresponse.cpp;h=4da67422fa221735ea234f64d7430e0d2e857d88;hp=0defebd5afb12a7fe3297649bd65b428e5bef22a;hb=b06cf07513fdd85e249398ebfce500fbf3dfb6a7;hpb=a4049d7c4126126ca3abd12b1aca8715e7006d44 diff --git a/source/response.cpp b/source/response.cpp index 0defebd..4da6742 100644 --- a/source/response.cpp +++ b/source/response.cpp @@ -20,7 +20,7 @@ Response::Response(Status s): string Response::str() const { - string result=format("%s %d %s\r\n", version_str(http_version), int(status), status); + string result=format("%s %d %s\r\n", version_str(http_version), static_cast(status), status); result+=str_common(); return result; @@ -31,30 +31,14 @@ Response Response::parse(const string &str) Response result; unsigned lf=str.find('\n'); - vector parts=split(str.substr(0, lf), ' '); + 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])); - 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; - - 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; - } + lf+=result.parse_headers(str.substr(lf+1)); result.parse_content(str.substr(lf+1));