[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2884] Send the HTTP payload only with a SUCCESSFUL st
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2884] Send the HTTP payload only with a SUCCESSFUL status code. |
Date: |
Tue, 14 Oct 2008 21:48:48 +0000 |
Revision: 2884
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2884
Author: gscrivano
Date: 2008-10-14 21:48:47 +0000 (Tue, 14 Oct 2008)
Log Message:
-----------
Send the HTTP payload only with a SUCCESSFUL status code.
Modified Paths:
--------------
trunk/myserver/include/protocol/http/http_response.h
trunk/myserver/src/http_handler/cgi/cgi.cpp
trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp
trunk/myserver/src/http_handler/isapi/isapi.cpp
trunk/myserver/src/http_handler/scgi/scgi.cpp
trunk/myserver/src/http_handler/wincgi/wincgi.cpp
trunk/myserver/src/protocol/http/http_response.cpp
trunk/myserver/tests/test_http_response.cpp
Modified: trunk/myserver/include/protocol/http/http_response.h
===================================================================
--- trunk/myserver/include/protocol/http/http_response.h 2008-10-13
21:59:48 UTC (rev 2883)
+++ trunk/myserver/include/protocol/http/http_response.h 2008-10-14
21:48:47 UTC (rev 2884)
@@ -1,7 +1,7 @@
/* -*- mode: c++ -*- */
/*
MyServer
-Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
@@ -48,6 +48,12 @@
*/
struct HttpResponseHeader : public HttpHeader
{
+ const static int INFORMATIONAL = 100;
+ const static int SUCCESSFUL = 200;
+ const static int REDIRECTION = 300;
+ const static int CLIENT_ERROR = 400;
+ const static int SERVER_ERROR = 500;
+
struct Entry
{
string *name;
@@ -91,6 +97,8 @@
HttpResponseHeader();
~HttpResponseHeader();
+ int getStatusType();
+
virtual string* getValue(const char* name, string* out);
virtual string* setValue(const char* name, const char* in);
void free();
Modified: trunk/myserver/src/http_handler/cgi/cgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/cgi/cgi.cpp 2008-10-13 21:59:48 UTC (rev
2883)
+++ trunk/myserver/src/http_handler/cgi/cgi.cpp 2008-10-14 21:48:47 UTC (rev
2884)
@@ -504,72 +504,75 @@
nbw += headerOffset - headerSize;
}
- /* Send the rest of the data until we can read from the pipe. */
- for(;;)
+ if (td->response.getStatusType () == HttpResponseHeader::SUCCESSFUL)
{
- int aliveProcess = 0;
+ /* Send the rest of the data until we can read from the pipe. */
+ for(;;)
+ {
+ int aliveProcess = 0;
- /* Process timeout. */
- if((int)(getTicks() - procStartTime) > cgiTimeout)
- {
- stdOutFile.close();
- stdInFile.close();
- chain.clearAllFilters();
- /* Remove the connection on sockets error. */
- cgiProc.terminateProcess();
- return 0;
- }
+ /* Process timeout. */
+ if((int)(getTicks() - procStartTime) > cgiTimeout)
+ {
+ stdOutFile.close();
+ stdInFile.close();
+ chain.clearAllFilters();
+ /* Remove the connection on sockets error. */
+ cgiProc.terminateProcess();
+ return 0;
+ }
- aliveProcess = cgiProc.isProcessAlive();
+ aliveProcess = cgiProc.isProcessAlive();
- /* Read data from the process standard output file. */
- if(stdOutFile.read(td->buffer2->getBuffer(),
- td->buffer2->getRealLength(),
- &nBytesRead))
- {
- stdOutFile.close();
- stdInFile.close();
- chain.clearAllFilters();
- /* Remove the connection on sockets error. */
- cgiProc.terminateProcess();
- return 0;
+ /* Read data from the process standard output file. */
+ if(stdOutFile.read(td->buffer2->getBuffer(),
+ td->buffer2->getRealLength(),
+ &nBytesRead))
+ {
+ stdOutFile.close();
+ stdInFile.close();
+ chain.clearAllFilters();
+ /* Remove the connection on sockets error. */
+ cgiProc.terminateProcess();
+ return 0;
+ }
+
+ if(!aliveProcess && !nBytesRead)
+ break;
+
+ if(nBytesRead &&
+ HttpDataHandler::appendDataToHTTPChannel(td,
+ td->buffer2->getBuffer(),
+ nBytesRead,
+ &(td->outputData),
+ &chain,
+ td->appendOutputs,
+ useChunks))
+ {
+ stdOutFile.close();
+ stdInFile.close();
+ chain.clearAllFilters();
+ /* Remove the connection on sockets error. */
+ cgiProc.terminateProcess();
+ return 0;
+ }
+
+ nbw += nBytesRead;
}
-
- if(!aliveProcess && !nBytesRead)
- break;
-
- if(nBytesRead &&
- HttpDataHandler::appendDataToHTTPChannel(td,
- td->buffer2->getBuffer(),
- nBytesRead,
- &(td->outputData),
- &chain,
- td->appendOutputs,
- useChunks))
+
+
+ /* Send the last null chunk if needed. */
+ if(useChunks && chain.write("0\r\n\r\n", 5, &nbw2))
{
stdOutFile.close();
stdInFile.close();
chain.clearAllFilters();
+
/* Remove the connection on sockets error. */
cgiProc.terminateProcess();
return 0;
}
-
- nbw += nBytesRead;
}
-
-
- /* Send the last null chunk if needed. */
- if(useChunks && chain.write("0\r\n\r\n", 5, &nbw2))
- {
- stdOutFile.close();
- stdInFile.close();
- chain.clearAllFilters();
-
- /* Remove the connection on sockets error. */
- cgiProc.terminateProcess();
- return 0;
- }
/* Update the Content-Length field for logging activity. */
td->sentData += nbw;
Modified: trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp 2008-10-13 21:59:48 UTC
(rev 2883)
+++ trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp 2008-10-14 21:48:47 UTC
(rev 2884)
@@ -618,67 +618,70 @@
}
}
- /*! Flush the data. */
- do
+ if (td->response.getStatusType () == HttpResponseHeader::SUCCESSFUL)
{
- if(con.tempOut.readFromFile(td->buffer->getBuffer(),
- td->buffer->getRealLength(), &nbr))
+ /*! Flush the data. */
+ do
{
- exit = 1;
- ret = 0;
- break;
- }
+ if(con.tempOut.readFromFile(td->buffer->getBuffer(),
+ td->buffer->getRealLength(), &nbr))
+ {
+ exit = 1;
+ ret = 0;
+ break;
+ }
- if(!td->appendOutputs)
- {
- u_long nbw2;
- if(nbr)
+ if(!td->appendOutputs)
{
- if(useChunks)
+ u_long nbw2;
+ if(nbr)
{
- ostringstream tmp;
- tmp << hex << nbr << "\r\n";
- td->response.contentLength.assign(tmp.str());
- if(chain.write(tmp.str().c_str(), tmp.str().length(), &nbw2))
+ if(useChunks)
{
+ ostringstream tmp;
+ tmp << hex << nbr << "\r\n";
+ td->response.contentLength.assign(tmp.str());
+ if(chain.write(tmp.str().c_str(), tmp.str().length(), &nbw2))
+ {
+ exit = 1;
+ ret = 0;
+ break;
+ }
+ }
+
+ if(chain.write(td->buffer->getBuffer(), nbr, &nbw2))
+ {
exit = 1;
ret = 0;
break;
}
- }
- if(chain.write(td->buffer->getBuffer(), nbr, &nbw2))
- {
- exit = 1;
- ret = 0;
- break;
+ if(useChunks && chain.write("\r\n", 2, &nbw2))
+ {
+ exit = 1;
+ ret = 0;
+ break;
+ }
}
-
- if(useChunks && chain.write("\r\n", 2, &nbw2))
+ }
+ else
+ {
+ u_long nbw = 0;
+ if(td->outputData.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
{
exit = 1;
ret = 0;
break;
}
}
- }
- else
+ }while(nbr);
+
+ if(useChunks && chain.write("0\r\n\r\n", 5, &nbw2))
{
- u_long nbw = 0;
- if(td->outputData.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
- {
- exit = 1;
- ret = 0;
- break;
- }
+ exit = 1;
+ ret = 0;
+ break;
}
- }while(nbr);
-
- if(useChunks && chain.write("0\r\n\r\n", 5, &nbw2))
- {
- exit = 1;
- ret = 0;
- break;
}
break;
Modified: trunk/myserver/src/http_handler/isapi/isapi.cpp
===================================================================
--- trunk/myserver/src/http_handler/isapi/isapi.cpp 2008-10-13 21:59:48 UTC
(rev 2883)
+++ trunk/myserver/src/http_handler/isapi/isapi.cpp 2008-10-14 21:48:47 UTC
(rev 2884)
@@ -310,7 +310,7 @@
ConnInfo->headerSent=1;
/*! If only the header was requested return. */
- if(ConnInfo->headerSent && ConnInfo->onlyHeader)
+ if(ConnInfo->headerSent && ConnInfo->onlyHeader ||
ConnInfo->td->response.getStatusType () == HttpResponseHeader::SUCCESSFUL)
return 0;
/*!Send the first chunk. */
Modified: trunk/myserver/src/http_handler/scgi/scgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/scgi/scgi.cpp 2008-10-13 21:59:48 UTC
(rev 2883)
+++ trunk/myserver/src/http_handler/scgi/scgi.cpp 2008-10-14 21:48:47 UTC
(rev 2884)
@@ -311,32 +311,34 @@
sentData += read - headerSize;
- for(;;)
+ if (td->response.getStatusType () == HttpResponseHeader::SUCCESSFUL)
{
- nbr = ctx->sock.recv(td->buffer2->getBuffer(),
- td->buffer2->getRealLength(),
- 0);
+ for(;;)
+ {
+ nbr = ctx->sock.recv(td->buffer2->getBuffer(),
+ td->buffer2->getRealLength(),
+ 0);
+
+ if(!nbr || (nbr == (u_long)-1))
+ break;
- if(!nbr || (nbr == (u_long)-1))
- break;
-
- if(appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- nbr,
- &(td->outputData),
- chain,
- td->appendOutputs,
- useChunks))
- return -1;
-
- sentData += nbr;
+ if(appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ nbr,
+ &(td->outputData),
+ chain,
+ td->appendOutputs,
+ useChunks))
+ return -1;
+
+ sentData += nbr;
+ }
+
+ if(!td->appendOutputs && useChunks)
+ {
+ if(chain->write("0\r\n\r\n", 5, &nbw))
+ return -1;
+ }
}
-
- if(!td->appendOutputs && useChunks)
- {
- if(chain->write("0\r\n\r\n", 5, &nbw))
- return -1;
- }
-
/* For logging activity. */
td->sentData += sentData;
Modified: trunk/myserver/src/http_handler/wincgi/wincgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/wincgi/wincgi.cpp 2008-10-13 21:59:48 UTC
(rev 2883)
+++ trunk/myserver/src/http_handler/wincgi/wincgi.cpp 2008-10-14 21:48:47 UTC
(rev 2884)
@@ -423,45 +423,47 @@
nbw += nbw2;
}
- /* Flush the rest of the file. */
- do
+ if (td->response.getStatusType () == HttpResponseHeader::SUCCESSFUL)
{
- OutFileHandle.readFromFile(buffer, td->buffer2->getLength(),
- &nBytesRead);
- if(nBytesRead)
+ /* Flush the rest of the file. */
+ do
{
- int ret;
- if(td->appendOutputs)
+ OutFileHandle.readFromFile(buffer, td->buffer2->getLength(),
+ &nBytesRead);
+ if(nBytesRead)
{
- ret = td->outputData.writeToFile(buffer, nBytesRead, &nbw);
- if(ret)
+ int ret;
+ if(td->appendOutputs)
{
- OutFileHandle.close();
- FilesUtility::deleteFile(outFilePath);
- FilesUtility::deleteFile(dataFilePath);
- chain.clearAllFilters();
- return 0;
- }
- }
- else
- {
- u_long nbw2;
- ret = chain.write((char*)buffer, nBytesRead, &nbw2);
- if(ret == -1)
+ ret = td->outputData.writeToFile(buffer, nBytesRead, &nbw);
+ if(ret)
+ {
+ OutFileHandle.close();
+ FilesUtility::deleteFile(outFilePath);
+ FilesUtility::deleteFile(dataFilePath);
+ chain.clearAllFilters();
+ return 0;
+ }
+ }
+ else
{
- OutFileHandle.close();
- FilesUtility::deleteFile(outFilePath);
- FilesUtility::deleteFile(dataFilePath);
- chain.clearAllFilters();
- return 0;
+ u_long nbw2;
+ ret = chain.write((char*)buffer, nBytesRead, &nbw2);
+ if(ret == -1)
+ {
+ OutFileHandle.close();
+ FilesUtility::deleteFile(outFilePath);
+ FilesUtility::deleteFile(dataFilePath);
+ chain.clearAllFilters();
+ return 0;
+ }
}
}
- }
- else
- break;
-
- }while(nBytesRead);
-
+ else
+ break;
+
+ }while(nBytesRead);
+ }
td->sentData += nbw;
chain.clearAllFilters();
Modified: trunk/myserver/src/protocol/http/http_response.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http_response.cpp 2008-10-13 21:59:48 UTC
(rev 2883)
+++ trunk/myserver/src/protocol/http/http_response.cpp 2008-10-14 21:48:47 UTC
(rev 2884)
@@ -276,3 +276,24 @@
return 0;
}
}
+
+/*!
+ *Get the kind of HTTP status code specified by the httpStatus variable.
+ *\return the HTTP status kind.
+ */
+int HttpResponseHeader::getStatusType()
+{
+ if (httpStatus < 200)
+ return HttpResponseHeader::INFORMATIONAL;
+
+ if (httpStatus < 300)
+ return HttpResponseHeader::SUCCESSFUL;
+
+ if (httpStatus < 400)
+ return HttpResponseHeader::REDIRECTION;
+
+ if (httpStatus < 500)
+ return HttpResponseHeader::CLIENT_ERROR;
+
+ return HttpResponseHeader::SERVER_ERROR;
+}
Modified: trunk/myserver/tests/test_http_response.cpp
===================================================================
--- trunk/myserver/tests/test_http_response.cpp 2008-10-13 21:59:48 UTC (rev
2883)
+++ trunk/myserver/tests/test_http_response.cpp 2008-10-14 21:48:47 UTC (rev
2884)
@@ -123,8 +123,27 @@
}
+ void testStatusType ()
+ {
+ HttpResponseHeader header;
+ header.httpStatus = 100;
+ CPPUNIT_ASSERT_EQUAL(header.getStatusType(),
HttpResponseHeader::INFORMATIONAL);
+
+ header.httpStatus = 200;
+ CPPUNIT_ASSERT_EQUAL(header.getStatusType(),
HttpResponseHeader::SUCCESSFUL);
+
+ header.httpStatus = 300;
+ CPPUNIT_ASSERT_EQUAL(header.getStatusType(),
HttpResponseHeader::REDIRECTION);
+
+ header.httpStatus = 400;
+ CPPUNIT_ASSERT_EQUAL(header.getStatusType(),
HttpResponseHeader::CLIENT_ERROR);
+
+ header.httpStatus = 500;
+ CPPUNIT_ASSERT_EQUAL(header.getStatusType(),
HttpResponseHeader::SERVER_ERROR);
+ }
+
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2884] Send the HTTP payload only with a SUCCESSFUL status code.,
Giuseppe Scrivano <=