]> git.tdb.fi Git - libs/net.git/blob - source/response.cpp
Style update: spaces around assignments
[libs/net.git] / source / response.cpp
1 /* $Id$
2
3 This file is part of libmsphttp
4 Copyright © 2008  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #include <msp/strings/formatter.h>
9 #include <msp/strings/utils.h>
10 #include "response.h"
11
12 using namespace std;
13
14 namespace Msp {
15 namespace Http {
16
17 Response::Response(Status s):
18         status(s)
19 { }
20
21 string Response::str() const
22 {
23         string result = format("%s %d %s\r\n", version_str(http_version), static_cast<int>(status), status);
24         result += str_common();
25
26         return result;
27 }
28
29 Response Response::parse(const string &str)
30 {
31         Response result;
32
33         unsigned lf = str.find('\n');
34         vector<string> parts = split(str.substr(0, lf), ' ', 2);
35         if(parts.size()<2)
36                 throw InvalidParameterValue("Invalid response");
37
38         result.http_version = parse_version(parts[0]);
39         result.status = static_cast<Status>(lexical_cast<unsigned>(parts[1]));
40
41         lf += result.parse_headers(str.substr(lf+1));
42
43         result.parse_content(str.substr(lf+1));
44
45         return result;
46 }
47
48 } // namespace Http
49 } // namespace Msp