return i->second;
}
-void Message::add_data(const string &d)
+void Message::add_content(const string &d)
{
- data+=d;
+ content+=d;
if(headers.count("content-type")==0)
set_header("content-type", "text/plain");
- set_header("content-length", lexical_cast(data.size()));
+ set_header("content-length", lexical_cast(content.size()));
}
-unsigned Message::parse_data(const string &d)
+void Message::set_user_data(const Variant &d)
+{
+ user_data=d;
+}
+
+unsigned Message::parse_content(const string &d)
{
if(complete)
return 0;
HeaderMap::const_iterator i=headers.find("content-length");
if(i!=headers.end())
{
- unsigned needed=lexical_cast<unsigned>(i->second)-data.size();
+ unsigned needed=lexical_cast<unsigned>(i->second)-content.size();
unsigned len=min(needed, d.size());
- data.append(d, 0, len);
+ content.append(d, 0, len);
if(len==needed)
complete=true;
unsigned lf=d.find('\n', pos);
if(lf==string::npos)
return pos;
- // XXX strtoul
- chunk_length=strtoul(strip(d.substr(pos, lf-pos)).c_str(), 0, 16);
+ chunk_length=lexical_cast<unsigned>(strip(d.substr(pos, lf-pos)), "x");
if(chunk_length==0)
complete=true;
pos=lf+1;
else
{
unsigned len=min(chunk_length, d.size()-pos);
- data.append(d, pos, len);
+ content.append(d, pos, len);
chunk_length-=len;
if((pos=d.find('\n', pos+len))!=string::npos)
++pos;
for(HeaderMap::const_iterator i=headers.begin(); i!=headers.end(); ++i)
result+=format("%s: %s\r\n", i->first, i->second);
result+="\r\n";
- result+=data;
+ result+=content;
return result;
}