23 #include "HttpResponseParser.h"
25 string* HttpResponseParser::headernames = NULL;
27 HttpResponseParser::HttpResponseParser() {
28 logger = Logger::getLogger(
"HttpResponseParser");
31 HttpResponseParser::~HttpResponseParser() {
37 HttpResponseParser::HttpResponseParser(
string vecstr,
string path)
40 StringUtil::split(vec, vecstr, (
"\n"));
41 if(HttpResponseParser::headernames==NULL)
43 HttpResponseParser::headernames =
new string();
44 ifstream ifs((path+
"http-res-headers").c_str(),ifstream::in);
46 while(getline(ifs,tempios,
'\n'))
48 HttpResponseParser::headernames->append(tempios);
50 logger <<
"Done reading header types" << endl;
56 bool contStarts =
false;
57 for(
unsigned int i=0;i<vec.size();i++)
60 vector<string> temp,vemp,memp;
62 if(vec.at(i)==
"\r" || vec.at(i)==
""|| vec.at(i)==
"\r\n")
67 StringUtil::split(temp, vec.at(i), (
": "));
71 StringUtil::replaceFirst(temp.at(1),
"\r",
"");
72 if(HttpResponseParser::headernames->find(temp.at(0)+
":")!=string::npos)
75 this->headers[temp.at(0)] = temp.at(1);
78 logger << (
"Not a valid header" + temp.at(0)) << endl;
83 string tem = vec.at(i);
87 vector<string> httpst;
88 StringUtil::split(httpst, tem, (
" "));
89 if(httpst.at(0).find(
"HTTP")==string::npos)
95 this->headers[
"Version"] = httpst.at(0);
96 this->headers[
"StatusCode"] = httpst.at(1);
97 this->headers[
"StatusMsg"] = httpst.at(2);
103 if(vec.at(i).find(
"<?")!=string::npos && vec.at(i).find(
"?>")!=string::npos)
105 temp = vec.at(i).substr(vec.at(i).find(
"?>")+2);
109 conten.append(vec.at(i));
115 this->content = conten;
116 if(this->content!=
"")
123 HttpResponseParser::HttpResponseParser(
string vecstr)
126 StringUtil::split(vec, vecstr, (
"\n"));
131 bool contStarts =
false;
132 for(
unsigned int i=0;i<vec.size();i++)
135 vector<string> temp,vemp,memp;
136 if((vec.at(i)==
"\r" || vec.at(i)==
""|| vec.at(i)==
"\r\n") && !contStarts)
141 StringUtil::split(temp, vec.at(i), (
": "));
142 if(temp.size()>1 && !contStarts)
145 StringUtil::replaceFirst(temp.at(1),
"\r",
"");
146 this->headers[temp.at(0)] = temp.at(1);
150 string tem = vec.at(i);
154 StringUtil::replaceFirst(tem,
"\r",
"");
155 vector<string> httpst;
156 StringUtil::split(httpst, tem, (
" "));
157 if(httpst.at(0).find(
"HTTP")==string::npos)
163 this->headers[
"Version"] = httpst.at(0);
164 this->headers[
"StatusCode"] = httpst.at(1);
165 this->headers[
"StatusMsg"] = httpst.at(2);
170 conten.append(vec.at(i));
176 this->content = conten;
177 if(this->content!=
"")