2 #include <msp/strings/utils.h>
11 Header::Header(const Message &msg, const string &n, Style s):
14 raw_value(msg.get_header(name))
19 Header::Header(const string &n, const string &rv, Style s):
27 Header::Style Header::get_default_style(const string &name)
29 if(!strcasecmp(name, "content-disposition"))
30 return VALUE_WITH_ATTRIBUTES;
31 else if(!strcasecmp(name, "content-type"))
32 return VALUE_WITH_ATTRIBUTES;
33 else if(!strcasecmp(name, "cookie"))
34 return KEY_VALUE_LIST;
35 else if(!strcasecmp(name, "set-cookie"))
36 return VALUE_WITH_ATTRIBUTES;
44 style = get_default_style(name);
46 if(style==SINGLE_VALUE)
49 value.value = strip(raw_value);
50 values.push_back(value);
54 char value_sep = (style==VALUE_WITH_ATTRIBUTES ? 0 : ',');
56 auto i = raw_value.cbegin();
57 while(i!=raw_value.cend())
62 if(style==KEY_VALUE_LIST)
66 for(; (i!=raw_value.end() && *i!=';' && *i!=value_sep); ++i) ;
67 value.value = strip(string(start, i));
68 if(value.value.empty())
69 throw invalid_argument("Header::parse");
72 while(i!=raw_value.end() && (*i!=',' || style==KEY_VALUE_LIST) && style!=LIST)
74 if(*i==';' || *i==',')
78 for(; (i!=raw_value.end() && *i!=';' && *i!=value_sep && *i!='='); ++i) ;
79 string pname = strip(string(start, i));
81 throw invalid_argument("Header::parse");
84 if(i!=raw_value.end() && *i=='=')
86 for(++i; (i!=raw_value.end() && isspace(*i)); ++i) ;
87 if(i==raw_value.end() || *i==';' || *i==value_sep)
88 throw invalid_argument("Header::parse");
93 for(; (i!=raw_value.end() && *i!='"'); ++i) ;
94 if(i==raw_value.end())
95 throw invalid_argument("Header::parse");
97 pvalue = string(start, i);
99 for(++i; (i!=raw_value.end() && *i!=';' && *i!=value_sep); ++i)
101 throw invalid_argument("Header::parse");
106 for(; (i!=raw_value.end() && *i!=';' && *i!=value_sep); ++i) ;
107 pvalue = strip(string(start, i));
111 value.parameters[pname] = pvalue;
114 values.push_back(value);
116 if(i!=raw_value.end() && (*i==';' || *i==','))