-/* $Id$
-
-This file is part of libmsphttp
-Copyright © 2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the LGPL
-*/
-
#include <msp/strings/formatter.h>
#include <msp/strings/utils.h>
#include "response.h"
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<int>(status), status);
+ result += str_common();
return result;
}
{
Response result;
- unsigned lf=str.find('\n');
- vector<string> parts=split(str.substr(0, lf), ' ');
+ unsigned lf = str.find('\n');
+ vector<string> 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<Status>(lexical_cast<unsigned>(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");
+ throw invalid_argument("Response::parse");
- result.set_header(str.substr(start, colon-start), strip(str.substr(colon+1, lf-colon-1)));
+ result.http_version = parse_version(parts[0]);
+ result.status = static_cast<Status>(lexical_cast<unsigned>(parts[1]));
- start=lf+1;
- }
+ lf += result.parse_headers(str.substr(lf+1));
result.parse_content(str.substr(lf+1));