]> git.tdb.fi Git - libs/net.git/blob - source/http/message.h
Add a dynamic receiver class for more flexible packet handling
[libs/net.git] / source / http / message.h
1 #ifndef MSP_HTTP_MESSAGE_H_
2 #define MSP_HTTP_MESSAGE_H_
3
4 #include <map>
5 #include <string>
6 #include <msp/core/variant.h>
7 #include <msp/net/mspnet_api.h>
8 #include "version.h"
9
10 namespace Msp {
11 namespace Http {
12
13 class MSPNET_API Message
14 {
15 protected:
16         typedef std::map<std::string, std::string> HeaderMap;
17
18         Version http_version = 0x11;
19         HeaderMap headers;
20         std::string content;
21         std::string::size_type chunk_length = 0;
22         bool complete = false;
23         Variant user_data;
24
25         Message() = default;
26 public:
27         virtual ~Message() = default;
28
29         void set_header(const std::string &, const std::string &);
30         bool has_header(const std::string &) const;
31         const std::string &get_header(const std::string &) const;
32         void add_content(const std::string &);
33         const std::string &get_content() const { return content; }
34         void set_user_data(const Variant &);
35         const Variant &get_user_data() const { return user_data; }
36         bool is_complete() const { return complete; }
37         unsigned parse_content(const std::string &);
38         virtual std::string str() const = 0;
39 protected:
40         unsigned parse_headers(const std::string &);
41         std::string str_common() const;
42         std::string normalize_header_name(const std::string &) const;
43 };
44
45 } // namespace Http
46 } // namespace Msp
47
48 #endif