myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-473


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-473-gf7999a9
Date: Fri, 22 Apr 2011 18:11:52 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  f7999a90b39d964a5e3aa9f70cef8a6bae7ac69a (commit)
      from  1452a920039a2faa8f93796cc417434b96ff4361 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit f7999a90b39d964a5e3aa9f70cef8a6bae7ac69a
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Apr 22 19:35:29 2011 +0200

    Modify handlers to use new HttpHandler class facilities.

diff --git a/myserver/include/http_handler/cgi/cgi.h 
b/myserver/include/http_handler/cgi/cgi.h
index d357aab..99f920d 100644
--- a/myserver/include/http_handler/cgi/cgi.h
+++ b/myserver/include/http_handler/cgi/cgi.h
@@ -41,6 +41,6 @@ private:
                 Process& cgiProc, bool onlyHeader, bool nph);
   int sendHeader (HttpThreadContext* td, Pipe &stdOutFile, FiltersChain& chain,
                   Process& cgiProc, bool onlyHeader, bool nph, u_long 
procStartTime,
-                  bool keepalive, bool useChunks, int *ret);
+                  bool *useChunks, int *ret);
 };
 #endif
diff --git a/myserver/include/http_handler/isapi/isapi.h 
b/myserver/include/http_handler/isapi/isapi.h
index efd1c48..a8ba3c6 100644
--- a/myserver/include/http_handler/isapi/isapi.h
+++ b/myserver/include/http_handler/isapi/isapi.h
@@ -111,6 +111,8 @@ typedef struct _EXTENSION_CONTROL_BLOCK
 
 struct ConnTableRecord
 {
+  bool keepalive;
+  bool useChunks;
   FiltersChain chain;
   BOOL Allocated;
   bool onlyHeader;
diff --git a/myserver/src/http_handler/cgi/cgi.cpp 
b/myserver/src/http_handler/cgi/cgi.cpp
index 4c820cb..2f4c7ad 100644
--- a/myserver/src/http_handler/cgi/cgi.cpp
+++ b/myserver/src/http_handler/cgi/cgi.cpp
@@ -290,19 +290,15 @@ int Cgi::sendData (HttpThreadContext* td, Pipe 
&stdOutFile, FiltersChain& chain,
   size_t nbw = 0;
   size_t nBytesRead = 0;
   u_long procStartTime;
-  bool useChunks = false;
-  bool keepalive = false;
   int ret = 0;
-
+  bool useChunks;
   /* Reset the auxiliaryBuffer length counter. */
   td->auxiliaryBuffer->setLength (0);
 
   procStartTime = getTicks ();
 
-  checkDataChunks (td, &keepalive, &useChunks);
-
   if (sendHeader (td, stdOutFile, chain, cgiProc, onlyHeader, nph,
-                  procStartTime, keepalive, useChunks, &ret))
+                  procStartTime, &useChunks, &ret))
     return ret;
 
   if (!nph && onlyHeader)
@@ -343,16 +339,15 @@ int Cgi::sendData (HttpThreadContext* td, Pipe 
&stdOutFile, FiltersChain& chain,
         break;
 
       if (nBytesRead)
-      td->sentData += HttpDataHandler::appendDataToHTTPChannel (td,
+        td->sentData += HttpDataHandler::appendDataToHTTPChannel (td,
                                                   
td->auxiliaryBuffer->getBuffer (),
                                                   nBytesRead,
                                                   chain,
                                                   useChunks);
     }
 
-  /* Send the last null chunk if needed.  */
-  if (useChunks && chain.getStream ()->write ("0\r\n\r\n", 5, &nbw))
-    return HttpDataHandler::RET_FAILURE;
+  MemoryStream memStream (td->auxiliaryBuffer);
+  td->sentData += completeHTTPResponse (td, memStream, chain, useChunks);
 
   return HttpDataHandler::RET_OK;
 }
@@ -361,10 +356,9 @@ int Cgi::sendData (HttpThreadContext* td, Pipe 
&stdOutFile, FiltersChain& chain,
   Send the HTTP header.
   \return nonzero if the reply is already complete.
  */
-int Cgi::sendHeader (HttpThreadContext *td, Pipe &stdOutFile, FiltersChain 
&chain,
-                     Process &cgiProc, bool onlyHeader, bool nph,
-                     u_long procStartTime, bool keepalive, bool useChunks,
-                     int *ret)
+int Cgi::sendHeader (HttpThreadContext *td, Pipe &stdOutFile,
+                     FiltersChain &chain, Process &cgiProc, bool onlyHeader,
+                     bool nph, u_long procStartTime, bool *useChunks, int *ret)
 {
   u_long headerSize = 0;
   bool headerCompleted = false;
@@ -443,15 +437,14 @@ int Cgi::sendHeader (HttpThreadContext *td, Pipe 
&stdOutFile, FiltersChain &chai
   /* Send the header.  */
   if (!nph)
     {
-      if (keepalive)
-        td->response.setValue ("Connection", "keep-alive");
-
       /* Send the header.  */
       if (headerSize)
         HttpHeaders::buildHTTPResponseHeaderStruct 
(td->auxiliaryBuffer->getBuffer (),
                                                     &td->response,
                                                     &(td->nBytesToRead));
         {
+          bool keepalive = false;
+
           string* location = td->response.getValue ("Location", NULL);
 
           /* If it is present "Location: foo" in the header then send a 
redirect
@@ -462,6 +455,7 @@ int Cgi::sendHeader (HttpThreadContext *td, Pipe 
&stdOutFile, FiltersChain &chai
               return 1;
             }
 
+          checkDataChunks (td, &keepalive, useChunks);
           HttpHeaders::sendHeader (td->response, *chain.getStream (),
                                    *td->buffer, td);
         }
diff --git a/myserver/src/http_handler/fastcgi/fastcgi.cpp 
b/myserver/src/http_handler/fastcgi/fastcgi.cpp
index 407cf11..1d3d109 100644
--- a/myserver/src/http_handler/fastcgi/fastcgi.cpp
+++ b/myserver/src/http_handler/fastcgi/fastcgi.cpp
@@ -77,9 +77,6 @@ int FastCgi::send (HttpThreadContext* td, const char* 
scriptpath,
   string moreArg;
   bool responseCompleted = false;
 
-  con.useChunks = false;
-  con.keepalive = false;
-
   con.td = td;
   con.headerSent = false;
 
@@ -205,7 +202,6 @@ int FastCgi::send (HttpThreadContext* td, const char* 
scriptpath,
       initialTicks = getTicks ();
 
       td->buffer->setLength (0);
-      checkDataChunks (td, &con.keepalive, &con.useChunks);
 
       do
         {
@@ -287,9 +283,8 @@ int FastCgi::send (HttpThreadContext* td, const char* 
scriptpath,
         }
       while (! exit);
 
-      /* Send the last null chunk if needed.  */
-      if (!responseCompleted && con.useChunks && !onlyHeader)
-        chain.getStream ()->write ("0\r\n\r\n", 5, &nbw);
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += completeHTTPResponse (td, memStream, chain, 
con.useChunks);
 
       chain.clearAllFilters ();
       con.sock.close ();
@@ -695,6 +690,7 @@ int FastCgi::handleHeader (FcgiContext* con, FiltersChain* 
chain, bool* response
         }
     }
 
+  checkDataChunks (con->td, &con->keepalive, &con->useChunks);
   if (HttpHeaders::sendHeader (con->td->response, *con->td->connection->socket,
                                *con->td->auxiliaryBuffer, con->td))
     {
diff --git a/myserver/src/http_handler/http_dir/http_dir.cpp 
b/myserver/src/http_handler/http_dir/http_dir.cpp
index 9d1e801..8aa34f7 100644
--- a/myserver/src/http_handler/http_dir/http_dir.cpp
+++ b/myserver/src/http_handler/http_dir/http_dir.cpp
@@ -325,10 +325,8 @@ int HttpDir::send (HttpThreadContext* td,
   ReadDirectory fd;
   FiltersChain chain;
   int lastSlash = 0;
-  bool useChunks = false;
   char* bufferloop;
   const char* cssFile;
-  bool keepalive = false;
   vector<HttpDir::FileStruct> files;
   size_t sortIndex;
   char sortType = 0;
@@ -362,8 +360,6 @@ int HttpDir::send (HttpThreadContext* td,
 
       lastSlash = td->request.uri.rfind ('/') + 1;
 
-      checkDataChunks (td, &keepalive, &useChunks);
-
       td->response.setValue ("content-type", "text/html");
 
       ignPattern = td->securityToken.getData ("http.dir.ignore",
@@ -384,6 +380,9 @@ int HttpDir::send (HttpThreadContext* td,
             }
         }
 
+      bool keepalive = false;
+      bool useChunks = false;
+      checkDataChunks (td, &keepalive, &useChunks);
       HttpHeaders::sendHeader (td->response, *td->connection->socket,
                                *td->buffer, td);
 
@@ -598,8 +597,8 @@ int HttpDir::send (HttpThreadContext* td,
         if (*bufferloop == '\\')
           *bufferloop = '/';
 
-      if (useChunks)
-        chain.getStream ()->write ("0\r\n\r\n", 5, &nbw);
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += completeHTTPResponse (td, memStream, chain, useChunks);
     }
   catch (exception & e)
     {
diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index 42ea59e..faa3561 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -318,8 +318,6 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     fastCopyAllowed = chain.isEmpty ()
       && !(td->http->getProtocolOptions () & Protocol::SSL);
 
-    checkDataChunks (td, &keepalive, &useChunks, fastCopyAllowed);
-
     if (! chain.hasModifiersFilters ())
       {
         ostringstream buffer;
@@ -327,6 +325,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
         td->response.contentLength.assign (buffer.str ());
       }
 
+    checkDataChunks (td, &keepalive, &useChunks, fastCopyAllowed);
     HttpHeaders::sendHeader (td->response, *td->connection->socket,
                              *td->buffer, td);
 
diff --git a/myserver/src/http_handler/isapi/isapi.cpp 
b/myserver/src/http_handler/isapi/isapi.cpp
index d14e5ea..cd0ec98 100644
--- a/myserver/src/http_handler/isapi/isapi.cpp
+++ b/myserver/src/http_handler/isapi/isapi.cpp
@@ -65,20 +65,14 @@ BOOL WINAPI ISAPI_ServerSupportFunctionExport (HCONN hConn, 
DWORD dwHSERRequest,
       mapInfo=(HSE_URL_MAPEX_INFO*)lpdwDataType;
       mapInfo->lpszPath = 0;
       tmp.assign (mapInfo->lpszPath);
-      ret=ConnInfo->td->http->getPath (tmp,(char*) lpvBuffer, 0);
+      ret = ConnInfo->td->http->getPath (tmp, (char*) lpvBuffer, 0);
       if (ret != 200)
         return 1;
 
-      mapInfo->cchMatchingURL=(DWORD)strlen ((char*) lpvBuffer);
-      mapInfo->cchMatchingPath=(DWORD)strlen (mapInfo->lpszPath);
+      mapInfo->cchMatchingURL = (DWORD) strlen ((char*) lpvBuffer);
+      mapInfo->cchMatchingPath = (DWORD) strlen (mapInfo->lpszPath);
       delete [] mapInfo->lpszPath;
       mapInfo->lpszPath = new char[tmp.length () + 1];
-      if (mapInfo->lpszPath == 0)
-        if (buffer==0)
-          {
-            SetLastError (ERROR_INSUFFICIENT_BUFFER);
-            return 0;
-          }
       strcpy (mapInfo->lpszPath, tmp.c_str ());
       mapInfo->dwFlags = HSE_URL_FLAGS_WRITE | HSE_URL_FLAGS_SCRIPT
         | HSE_URL_FLAGS_EXECUTE;
@@ -86,7 +80,7 @@ BOOL WINAPI ISAPI_ServerSupportFunctionExport (HCONN hConn, 
DWORD dwHSERRequest,
 
     case HSE_REQ_MAP_URL_TO_PATH:
       if (((char*) lpvBuffer)[0])
-        strcpy (uri,(char*) lpvBuffer);
+        strcpy (uri, (char*) lpvBuffer);
       else
         lstrcpyn (uri,ConnInfo->td->request.uri.c_str (),
                  (int) ConnInfo->td->request.uri.length ()
@@ -133,15 +127,15 @@ BOOL WINAPI ISAPI_ServerSupportFunctionExport (HCONN 
hConn, DWORD dwHSERRequest,
       break;
 
     case HSE_REQ_DONE_WITH_SESSION:
-      ConnInfo->td->response.httpStatus=*(DWORD*)lpvBuffer;
+      ConnInfo->td->response.httpStatus = *(DWORD*) lpvBuffer;
       SetEvent (ConnInfo->ISAPIDoneEvent);
       break;
 
     case HSE_REQ_IS_KEEP_CONN:
       if (ConnInfo->td->request.isKeepAlive ())
-        *((BOOL*)lpvBuffer)=1;
+        *((BOOL*)lpvBuffer) = 1;
       else
-        *((BOOL*)lpvBuffer)=0;
+        *((BOOL*)lpvBuffer) = 0;
       break;
 
     default:
@@ -204,11 +198,9 @@ int Isapi::SendHeader (HttpThreadContext* td,ConnectionPtr 
a,char *data)
 BOOL WINAPI ISAPI_WriteClientExport (HCONN hConn, LPVOID Buffer, LPDWORD 
lpdwBytes,
                                     DWORD /*!dwReserved*/)
 {
-  int keepalive;
   char* buffer;
   ConnTableRecord *ConnInfo;
-  char chunkSize[15];
-  size_t nbw=0;
+  size_t nbw = 0;
 
   if (*lpdwBytes == 0)
     return HttpDataHandler::RET_FAILURE;
@@ -228,14 +220,13 @@ BOOL WINAPI ISAPI_WriteClientExport (HCONN hConn, LPVOID 
Buffer, LPDWORD lpdwByt
     ((Vhost*)(ConnInfo->td->connection->host))->warningsLogWrite (_("ISAPI: 
internal error"));
     return HttpDataHandler::RET_FAILURE;
   }
-  keepalive = connection && (!strcasecmp (connection->value.c_str (), 
"keep-alive")) ;
 
   /*If the HTTP header was sent do not send it again. */
   if (!ConnInfo->headerSent)
     {
       int headerSize = 0;
       u_long size = (u_long) strlen (buffer);
-      strncat (buffer, (char*)Buffer, *lpdwBytes);
+      strncat (buffer, (char *) Buffer, *lpdwBytes);
       ConnInfo->headerSize += *lpdwBytes;
       if (buffer[0] == '\r')
         {
@@ -266,103 +257,61 @@ BOOL WINAPI ISAPI_WriteClientExport (HCONN hConn, LPVOID 
Buffer, LPDWORD lpdwByt
                 }
             }
         }
-      /*!
-       *Handle the HTTP header if exists.
+      /*
+        Handle the HTTP header if exists.
        */
       if (! headerSize)
         nbw = *lpdwBytes;
       else
         {
-          int len = ConnInfo->headerSize-headerSize;
+          int len = ConnInfo->headerSize - headerSize;
 
           HttpHeaders::buildHTTPResponseHeaderStruct
             (ConnInfo->td->buffer->getBuffer (), &ConnInfo->td->response,
              &(ConnInfo->td->nBytesToRead));
 
-          if (keepalive)
-            {
-              HttpResponseHeader::Entry *e;
-              e = ConnInfo->td->response.other.get ("transfer-encoding");
-              if (e)
-                e->value.assign ("chunked");
-              else
-                {
-                  e = new HttpResponseHeader::Entry ();
-                  e->name.assign ("transfer-encoding");
-                  e->value.assign ("chunked");
-                  ConnInfo->td->response.other.put (e->name, e);
-                }
-            }
-          else
-            ConnInfo->td->response.setValue ("connection", "Close");
-
+          HttpDataHandler::checkDataChunks (ConnInfo->td, &ConnInfo->keepalive,
+                                            &ConnInfo->useChunks);
           if (HttpHeaders::sendHeader (ConnInfo->td->response,
                                        *ConnInfo->td->connection->socket,
                                        *ConnInfo->td->auxiliaryBuffer,
                                        ConnInfo->td))
             return HttpDataHandler::RET_FAILURE;
-          /*! Save the headerSent status. */
-          ConnInfo->headerSent=1;
 
-          /*! If only the header was requested return. */
+          /* Save the headerSent status.  */
+          ConnInfo->headerSent = 1;
+
+          /* If only the header was requested return.  */
           if (ConnInfo->headerSent && ConnInfo->onlyHeader
               || ConnInfo->td->response.getStatusType ()
               == HttpResponseHeader::SUCCESSFUL)
             return 0;
 
-          /*!Send the first chunk. */
+          size_t written = 0;
           if (len)
-            {
-              /*! With keep-alive connections use chunks.*/
-              if (keepalive)
-                {
-                  sprintf (chunkSize, "%x\r\n", len);
-                  if (ConnInfo->chain.getStream ()->write (chunkSize,
-                                                           (int) strlen 
(chunkSize), &nbw))
-                    return HttpDataHandler::RET_FAILURE;
-                }
-
-              if (ConnInfo->chain.write ((char*)(buffer + headerSize),
-                                         len, &nbw))
-                return HttpDataHandler::RET_FAILURE;
-              ConnInfo->dataSent += nbw;
-
-              /*! Send the chunk footer.  */
-              if (keepalive)
-                {
-                  if (ConnInfo->chain.getStream ()->write ("\r\n", 2, &nbw))
-                    return HttpDataHandler::RET_FAILURE;
-                }
-            }
+            written =
+              HttpDataHandler::appendDataToHTTPChannel (ConnInfo->td,
+                                                        buffer + headerSize,
+                                                        len,
+                                                        ConnInfo->chain,
+                                                        ConnInfo->useChunks);
+          ConnInfo->td->sentData += written;
+
+          *lpdwBytes = written;
         }
     }
-  else/*!Continue to send data chunks*/
+  else
     {
-      if (keepalive)
-        {
-          sprintf (chunkSize, "%x\r\n", *lpdwBytes);
-          nbw = ConnInfo->connection->socket->send (chunkSize,
-                                                    (int) strlen (chunkSize), 
0);
-          if ((nbw == (size_t) -1) || (! nbw))
-            return HttpDataHandler::RET_FAILURE;
-        }
-
-      if (ConnInfo->chain.write ((char*)Buffer,*lpdwBytes, &nbw))
-        return HttpDataHandler::RET_FAILURE;
-      ConnInfo->dataSent += nbw;
-
-      if (keepalive)
-        {
-          nbw = ConnInfo->connection->socket->send ("\r\n", 2, 0);
-          if ((nbw == (size_t)-1) || (!nbw))
-            return HttpDataHandler::RET_FAILURE;
-        }
+      size_t written =
+        HttpDataHandler::appendDataToHTTPChannel (ConnInfo->td,
+                                                  (const char *) Buffer,
+                                                  *lpdwBytes,
+                                                  ConnInfo->chain,
+                                                  ConnInfo->useChunks);
+      ConnInfo->td->sentData += written;
+      *lpdwBytes = written;
     }
 
-  *lpdwBytes = nbw;
-
-  ConnInfo->td->sentData += ConnInfo->dataSent;
-
   return HttpDataHandler::RET_OK;
 }
 
@@ -389,12 +338,11 @@ BOOL WINAPI ISAPI_ReadClientExport (HCONN hConn, LPVOID 
lpvBuffer,
 
   if (ConnInfo == NULL)
     {
-      ((Vhost*)(ConnInfo->td->connection->host))->warningsLogWrite
-        (_("ISAPI: internal error"));
+      ConnInfo->td->connection->host->warningsLogWrite (_("ISAPI: internal 
error"));
       return HttpDataHandler::RET_FAILURE;
     }
 
-  ConnInfo->td->inputData.read ((char*) lpvBuffer, *lpdwSize, &numRead);
+  ConnInfo->td->inputData.read ((char *) lpvBuffer, *lpdwSize, &numRead);
 
   if (numRead < 0)
     {
@@ -878,8 +826,10 @@ int Isapi::send (HttpThreadContext* td,
       HttpRequestHeader::Entry *connection
         = connTable[connIndex].td->request.other.get ("connection");
 
-      if (connection && !strcasecmp (connection->value.c_str (), "keep-alive"))
-        connTable[connIndex].chain.getStream ()->write ("0\r\n\r\n", 5, &nbw);
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += completeHTTPResponse (td, memStream,
+                                            connTable[connIndex].chain,
+                                            connTable[connIndex].useChunks);
 
       switch (ret)
         {
diff --git a/myserver/src/http_handler/mscgi/mscgi.cpp 
b/myserver/src/http_handler/mscgi/mscgi.cpp
index 9d0f9ff..7680dc5 100644
--- a/myserver/src/http_handler/mscgi/mscgi.cpp
+++ b/myserver/src/http_handler/mscgi/mscgi.cpp
@@ -74,8 +74,6 @@ int MsCgi::send (HttpThreadContext* td, const char* exec, 
const char* cmdLine,
   data.error = false;
   data.filtersChain = &chain;
   data.headerSent = false;
-  data.keepAlive = false;
-  data.useChunks = false;
 
   if (!(td->permissions & MYSERVER_PERMISSION_EXECUTE))
     return td->http->sendAuth ();
@@ -103,7 +101,6 @@ int MsCgi::send (HttpThreadContext* td, const char* exec, 
const char* cmdLine,
                                                              
td->connection->socket,
                                                              &nbw, 1);
 
-      checkDataChunks (td, &(data.keepAlive), &(data.useChunks));
       try
         {
           hinstLib.loadLibrary (exec, 0);
@@ -135,8 +132,8 @@ int MsCgi::send (HttpThreadContext* td, const char* exec, 
const char* cmdLine,
           return td->http->raiseHTTPError (data.errorPage);
         }
 
-      if (data.useChunks && !data.error)
-        chain.getStream ()->write ("0\r\n\r\n", 5, &nbw);
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += completeHTTPResponse (td, memStream, chain, 
data.useChunks);
 
       if (!data.error)
         return HttpDataHandler::RET_FAILURE;
@@ -161,6 +158,7 @@ int MsCgi::write (const char* data, size_t len, MsCgiData* 
mcd)
   if (mcd->error)
     return 1;
 
+  checkDataChunks (mcd->td, &mcd->keepAlive, &mcd->useChunks);
   if (!mcd->headerSent && sendHeader (mcd))
     return 1;
 
diff --git a/myserver/src/http_handler/proxy/proxy.cpp 
b/myserver/src/http_handler/proxy/proxy.cpp
index 03e382d..0c95fb8 100644
--- a/myserver/src/http_handler/proxy/proxy.cpp
+++ b/myserver/src/http_handler/proxy/proxy.cpp
@@ -215,17 +215,8 @@ int Proxy::flushToClient (HttpThreadContext* td, Socket& 
client,
 
   /* At this point we can modify the response struct before send it to the
      client.  */
-  checkDataChunks (td, &keepalive, &useChunks);
-  if (td->response.contentLength.length ())
-    useChunks = false;
-
-  td->response.setValue ("Connection", keepalive ? "keep-alive" : "close");
-
-  if (useChunks)
-    td->response.setValue ("Transfer-encoding", "chunked");
-  else
-    td->response.clearValue ("Transfer-encoding");
 
+  checkDataChunks (td, &keepalive, &useChunks, 
td->response.contentLength.length ());
   u_long hdrLen = HttpHeaders::buildHTTPResponseHeader (td->buffer->getBuffer 
(),
                                                         &td->response);
 
@@ -345,8 +336,9 @@ int Proxy::readPayLoad (HttpThreadContext* td,
             break;
         }
     }
-  if (useChunks)
-    out->getStream ()->write ("0\r\n\r\n", 5, &nbw);
+
+  MemoryStream memStream (td->auxiliaryBuffer);
+  td->sentData += completeHTTPResponse (td, memStream, *out, useChunks);
 
   return HttpDataHandler::RET_OK;
 }
diff --git a/myserver/src/http_handler/scgi/scgi.cpp 
b/myserver/src/http_handler/scgi/scgi.cpp
index a7d1e06..009d006 100644
--- a/myserver/src/http_handler/scgi/scgi.cpp
+++ b/myserver/src/http_handler/scgi/scgi.cpp
@@ -218,8 +218,6 @@ int Scgi::sendResponse (ScgiContext* ctx, bool onlyHeader, 
FiltersChain* chain)
   size_t nbw, nbr;
   HttpThreadContext* td = ctx->td;
 
-  checkDataChunks (td, &keepalive, &useChunks);
-
   for (;;)
     {
       while (!ctx->sock.bytesToRead ())
@@ -259,6 +257,7 @@ int Scgi::sendResponse (ScgiContext* ctx, bool onlyHeader, 
FiltersChain* chain)
                                                 &td->response,
                                                 &(td->nBytesToRead));
 
+  checkDataChunks (td, &keepalive, &useChunks);
   HttpHeaders::sendHeader (td->response, *td->connection->socket,
                            *td->auxiliaryBuffer, td);
 
@@ -286,8 +285,8 @@ int Scgi::sendResponse (ScgiContext* ctx, bool onlyHeader, 
FiltersChain* chain)
                                      nbr, *chain, useChunks);
         }
 
-      if (useChunks)
-        chain->getStream ()->write ("0\r\n\r\n", 5, &nbw);
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += completeHTTPResponse (td, memStream, *chain, useChunks);
     }
 
   return HttpDataHandler::RET_OK;
diff --git a/myserver/src/http_handler/wincgi/wincgi.cpp 
b/myserver/src/http_handler/wincgi/wincgi.cpp
index e96b278..00da485 100644
--- a/myserver/src/http_handler/wincgi/wincgi.cpp
+++ b/myserver/src/http_handler/wincgi/wincgi.cpp
@@ -28,6 +28,7 @@
 #include <include/base/string/stringutils.h>
 #include <include/filter/filters_chain.h>
 #include <include/base/safetime/safetime.h>
+#include <include/filter/filters_chain.h>
 
 #ifdef WIN32
 # include <direct.h>
@@ -64,6 +65,7 @@ int WinCgi::send (HttpThreadContext* td, const char* 
scriptpath,
                   const char *cgipath, bool /*execute*/, bool onlyHeader)
 {
 #ifdef WIN32
+  bool keepalive, useChunks;
   FiltersChain chain;
   Process proc;
   size_t nbr;
@@ -295,11 +297,7 @@ int WinCgi::send (HttpThreadContext* td, const char* 
scriptpath,
 
       HttpHeaders::buildHTTPResponseHeaderStruct (buffer, &td->response, 
&(td->nBytesToRead));
 
-      /*
-       *Always specify the size of the HTTP contents.
-       */
-      stream << OutFileHandle.getFileSize () - headerSize;
-      td->response.contentLength.assign (stream.str ());
+      checkDataChunks (td, &keepalive, &useChunks);
       HttpHeaders::sendHeader (td->response, *chain.getStream (),
                                *td->buffer, td);
 
@@ -312,10 +310,11 @@ int WinCgi::send (HttpThreadContext* td, const char* 
scriptpath,
           return HttpDataHandler::RET_OK;
         }
 
-      size_t written;
-      chain.write ((char*)(buffer + headerSize), nBytesRead - headerSize,
-                   &written);
-      td->dataSent += written;
+      td->sentData += HttpDataHandler::appendDataToHTTPChannel (td,
+                                                                buffer + 
headerSize,
+                                                                nBytesRead - 
headerSize,
+                                                                chain, 
useChunks);
+
 
       if (td->response.getStatusType () == HttpResponseHeader::SUCCESSFUL)
         {
@@ -327,12 +326,19 @@ int WinCgi::send (HttpThreadContext* td, const char* 
scriptpath,
               if (! nBytesRead)
                 break;
 
-              chain.write ((char*) buffer, nBytesRead, &nbw);
+              td->sentData +=
+                HttpDataHandler::appendDataToHTTPChannel (td, buffer,
+                                                          nBytesRead, chain,
+                                                          useChunks);
+
               td->sentData += nbw;
             }
           while (nBytesRead);
         }
 
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += completeHTTPResponse (td, memStream, chain, useChunks);
+
       chain.clearAllFilters ();
       OutFileHandle.close ();
       FilesUtility::deleteFile (outFilePath);
diff --git a/myserver/src/protocol/http/webdav/webdav.cpp 
b/myserver/src/protocol/http/webdav/webdav.cpp
index dbacd61..cd1d422 100644
--- a/myserver/src/protocol/http/webdav/webdav.cpp
+++ b/myserver/src/protocol/http/webdav/webdav.cpp
@@ -302,12 +302,9 @@ int WebDAV::propfind (HttpThreadContext* td)
 
       ff->chain (&chain, filters, td->connection->socket, &nbw, 1);
 
-      HttpDataHandler::checkDataChunks (td, &keepalive, &useChunks);
       td->response.httpStatus = 207;
-      if (keepalive)
-        td->response.setValue ("connection", "keep-alive");
-      else
-        td->response.setValue ("connection", "close");
+
+      HttpDataHandler::checkDataChunks (td, &keepalive, &useChunks);
       HttpHeaders::sendHeader (td->response, *chain.getStream (), *td->buffer, 
td);
 
       /* Determine the Depth.  */
@@ -342,8 +339,9 @@ int WebDAV::propfind (HttpThreadContext* td)
             break;
         }
 
-      if (useChunks)
-        chain.getStream ()->write ("0\r\n\r\n", 5, &nbw2);
+      MemoryStream memStream (td->auxiliaryBuffer);
+      td->sentData += HttpDataHandler::completeHTTPResponse (td, memStream,
+                                                             chain, useChunks);
 
       return HttpDataHandler::RET_OK;
     }
@@ -619,18 +617,9 @@ int WebDAV::lock (HttpThreadContext* td)
 
       ff->chain (&chain, filters, td->connection->socket, &nbw, 1);
 
-      HttpDataHandler::checkDataChunks (td, &keepalive, &useChunks);
       td->response.httpStatus = 201;
 
-      if (keepalive)
-        td->response.setValue ("connection", "keep-alive");
-      else
-        td->response.setValue ("connection", "close");
-
-        td->response.setValue ("Lock-Token", urn);
-
-        td->response.setValue ("Content-Type", "text/xml");
-
+      HttpDataHandler::checkDataChunks (td, &keepalive, &useChunks);
       HttpHeaders::sendHeader (td->response, *chain.getStream (), *td->buffer, 
td);
 
       string lc = "http://"; + *td->request.getValue ("Host", NULL) + 
td->request.uri;

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/http_handler/cgi/cgi.h           |    2 +-
 myserver/include/http_handler/isapi/isapi.h       |    2 +
 myserver/src/http_handler/cgi/cgi.cpp             |   28 ++---
 myserver/src/http_handler/fastcgi/fastcgi.cpp     |   10 +-
 myserver/src/http_handler/http_dir/http_dir.cpp   |   11 +-
 myserver/src/http_handler/http_file/http_file.cpp |    3 +-
 myserver/src/http_handler/isapi/isapi.cpp         |  136 +++++++--------------
 myserver/src/http_handler/mscgi/mscgi.cpp         |    8 +-
 myserver/src/http_handler/proxy/proxy.cpp         |   16 +--
 myserver/src/http_handler/scgi/scgi.cpp           |    7 +-
 myserver/src/http_handler/wincgi/wincgi.cpp       |   26 +++--
 myserver/src/protocol/http/webdav/webdav.cpp      |   23 +---
 12 files changed, 98 insertions(+), 174 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]