Fix HTTP::Parser to no longer send empty headers.

This commit is contained in:
Thulinma 2012-08-26 21:19:48 +02:00
parent 516c8bf091
commit 84db148405

View file

@ -30,8 +30,10 @@ std::string HTTP::Parser::BuildRequest(){
if (protocol.size() < 5 || protocol.substr(0, 4) != "HTTP"){protocol = "HTTP/1.0";} if (protocol.size() < 5 || protocol.substr(0, 4) != "HTTP"){protocol = "HTTP/1.0";}
std::string tmp = method+" "+url+" "+protocol+"\n"; std::string tmp = method+" "+url+" "+protocol+"\n";
for (it=headers.begin(); it != headers.end(); it++){ for (it=headers.begin(); it != headers.end(); it++){
if ((*it).first != "" && (*it).second != ""){
tmp += (*it).first + ": " + (*it).second + "\n"; tmp += (*it).first + ": " + (*it).second + "\n";
} }
}
tmp += "\n" + body; tmp += "\n" + body;
return tmp; return tmp;
} }
@ -48,8 +50,10 @@ std::string HTTP::Parser::BuildResponse(std::string code, std::string message){
if (protocol.size() < 5 || protocol.substr(0, 4) != "HTTP"){protocol = "HTTP/1.0";} if (protocol.size() < 5 || protocol.substr(0, 4) != "HTTP"){protocol = "HTTP/1.0";}
std::string tmp = protocol+" "+code+" "+message+"\n"; std::string tmp = protocol+" "+code+" "+message+"\n";
for (it=headers.begin(); it != headers.end(); it++){ for (it=headers.begin(); it != headers.end(); it++){
if ((*it).first != "" && (*it).second != ""){
tmp += (*it).first + ": " + (*it).second + "\n"; tmp += (*it).first + ": " + (*it).second + "\n";
} }
}
tmp += "\n"; tmp += "\n";
tmp += body; tmp += body;
return tmp; return tmp;