Fixed a bug in HTTP parsing if data did not arrive in a nice way.

This commit is contained in:
Thulinma 2012-09-30 13:52:12 +02:00
parent ee034c363a
commit 619b9533bd
4 changed files with 45 additions and 0 deletions

View file

@ -241,6 +241,15 @@ namespace Connector_HTTP{
while (connconn.count(uid) && connconn[uid]->conn->connected() && conn->connected()){ while (connconn.count(uid) && connconn[uid]->conn->connected() && conn->connected()){
conn->spool(); conn->spool();
if (connconn[uid]->conn->Received().size() || connconn[uid]->conn->spool()){ if (connconn[uid]->conn->Received().size() || connconn[uid]->conn->spool()){
//make sure we end in a \n
if (*(connconn[uid]->conn->Received().get().rbegin()) != '\n'){
std::string tmp = connconn[uid]->conn->Received().get();
connconn[uid]->conn->Received().get().clear();
if (connconn[uid]->conn->Received().size()){
connconn[uid]->conn->Received().get().insert(0, tmp);
}
continue;
}
//check if the whole response was received //check if the whole response was received
if (H.Read(connconn[uid]->conn->Received().get())){ if (H.Read(connconn[uid]->conn->Received().get())){
break;//continue down below this while loop break;//continue down below this while loop
@ -330,6 +339,15 @@ namespace Connector_HTTP{
HTTP::Parser Client; HTTP::Parser Client;
while (conn->connected()){ while (conn->connected()){
if (conn->Received().size() || conn->spool()){ if (conn->Received().size() || conn->spool()){
//make sure it ends in a \n
if (*(conn->Received().get().rbegin()) != '\n'){
std::string tmp = conn->Received().get();
conn->Received().get().clear();
if (conn->Received().size()){
conn->Received().get().insert(0, tmp);
}
continue;
}
if (Client.Read(conn->Received().get())){ if (Client.Read(conn->Received().get())){
std::string handler = getHTTPType(Client); std::string handler = getHTTPType(Client);
long long int startms = Util::getMS(); long long int startms = Util::getMS();

View file

@ -180,6 +180,15 @@ namespace Connector_HTTP{
while (conn.connected()){ while (conn.connected()){
if (conn.spool() || conn.Received().size()){ if (conn.spool() || conn.Received().size()){
//make sure it ends in a \n
if (*(conn.Received().get().rbegin()) != '\n'){
std::string tmp = conn.Received().get();
conn.Received().get().clear();
if (conn.Received().size()){
conn.Received().get().insert(0, tmp);
}
continue;
}
if (HTTP_R.Read(conn.Received().get())){ if (HTTP_R.Read(conn.Received().get())){
#if DEBUG >= 4 #if DEBUG >= 4
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;

View file

@ -42,6 +42,15 @@ namespace Connector_HTTP{
//only parse input if available or not yet init'ed //only parse input if available or not yet init'ed
if (!inited){ if (!inited){
if (conn.Received().size() || conn.spool()){ if (conn.Received().size() || conn.spool()){
//make sure it ends in a \n
if (*(conn.Received().get().rbegin()) != '\n'){
std::string tmp = conn.Received().get();
conn.Received().get().clear();
if (conn.Received().size()){
conn.Received().get().insert(0, tmp);
}
continue;
}
if (HTTP_R.Read(conn.Received().get())){ if (HTTP_R.Read(conn.Received().get())){
#if DEBUG >= 4 #if DEBUG >= 4
std::cout << "Received request: " << HTTP_R.getUrl() << std::endl; std::cout << "Received request: " << HTTP_R.getUrl() << std::endl;

View file

@ -497,6 +497,15 @@ int main(int argc, char ** argv){
break; break;
} }
if (it->C.spool() || it->C.Received().size()){ if (it->C.spool() || it->C.Received().size()){
if (*(it->C.Received().get().rbegin()) != '\n'){
std::string tmp = it->C.Received().get();
it->C.Received().get().clear();
if (it->C.Received().size()){
it->C.Received().get().insert(0, tmp);
}
continue;
}
if (it->H.Read(it->C.Received().get())){ if (it->H.Read(it->C.Received().get())){
Response.null(); //make sure no data leaks from previous requests Response.null(); //make sure no data leaks from previous requests
if (it->clientMode){ if (it->clientMode){