Browse Source

Merge pull request #6420 from wangkx/content_length_64

HPCC-12127 Use 64-bit integer for HTTP Content-Length header

Reviewed-By: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 10 years ago
parent
commit
988d2fb3a4

+ 2 - 2
esp/bindings/SOAP/Platform/soapbind.cpp

@@ -147,7 +147,7 @@ int CHttpSoapBinding::onSoapRequest(CHttpRequest* request, CHttpResponse* respon
     //response->setContentType(soapFault->get_content_type());
     response->setContentType(HTTP_TYPE_TEXT_XML_UTF8);
     response->setContent(soapFault->get_text());
-    DBGLOG("Sending SOAP Fault(%u): %s", response->getContentLength(), response->queryContent());
+    DBGLOG("Sending SOAP Fault(%"I64F"d): %s", response->getContentLength(), response->queryContent());
     {
         EspTimeSection sendtime("send fault [CHttpSoapBinding::onSoapRequest]");
         response->send();
@@ -226,7 +226,7 @@ int CHttpSoapBinding::HandleSoapRequest(CHttpRequest* request, CHttpResponse* re
     response->setContentType(soapresponse->get_content_type());
     response->setContent(soapresponse->get_text());
     
-    DBGLOG("Sending SOAP Response(%u)", response->getContentLength());
+    DBGLOG("Sending SOAP Response(%"I64F"d)", response->getContentLength());
     {
         EspTimeSection sendtime("send response [CHttpSoapBinding::HandleSoapRequest]");
         response->send();

+ 33 - 0
esp/bindings/bindutil.cpp

@@ -259,6 +259,39 @@ int Utils::getLine(int total_len, int cur_pos, const char* buf, int& oneline_len
     return cur_pos;
 }
 
+__int64 Utils::getLine(__int64 total_len, __int64 cur_pos, const char* buf, int& oneline_len)
+{
+    oneline_len = 0;
+    if(cur_pos >= total_len)
+    {
+        return total_len;
+    }
+
+    while(cur_pos < total_len && buf[cur_pos] != '\r' && buf[cur_pos] != '\n')
+    {
+        oneline_len++;
+        cur_pos++;
+    }
+
+    if(cur_pos == total_len)
+        return total_len;
+
+    if(buf[cur_pos] == '\r')
+    {
+        cur_pos++;
+    }
+
+    if(cur_pos == total_len)
+        return total_len;
+
+    if(buf[cur_pos] == '\n')
+    {
+        cur_pos++;
+    }
+
+    return cur_pos;
+}
+
 int Utils::strncasecmp(const char* s1, const char* s2, register size32_t n) 
 {
     bool s1isnull = (s1 == NULL);

+ 1 - 0
esp/bindings/bindutil.hpp

@@ -34,6 +34,7 @@ public:
     static char* getWord(char* oneline, char* & oneword, const char* separators, bool tws=false);
     static void parseNVPair(const char* nv, StringBuffer& name, StringBuffer& value);
     static int getLine(int total_len, int cur_len, const char* buf, int & oneline_len);
+    static __int64 getLine(__int64 total_len, __int64 cur_len, const char* buf, int & oneline_len);
     static int strncasecmp(const char* s1, const char* s2, register size32_t n);
     static int strcasecmp(const char* s1, const char* s2);
     static const char *stristr(const char *haystack, const char *needle);

+ 4 - 4
esp/bindings/http/platform/httpservice.cpp

@@ -487,10 +487,10 @@ int CEspHttpServer::processRequest()
     catch (...)
     {
         StringBuffer content_type;
-        unsigned len = m_request->getContentLength();
+        __int64 len = m_request->getContentLength();
         DBGLOG("Unknown Exception - processing request");
-        DBGLOG("METHOD: %s, PATH: %s, TYPE: %s, CONTENT-LENGTH: %d", m_request->queryMethod(), m_request->queryPath(), m_request->getContentType(content_type).str(), len);
-        if (len)
+        DBGLOG("METHOD: %s, PATH: %s, TYPE: %s, CONTENT-LENGTH: %"I64F"d", m_request->queryMethod(), m_request->queryPath(), m_request->getContentType(content_type).str(), len);
+        if (len > 0)
             m_request->logMessage(LOGCONTENT, "HTTP request content received:\n");
         return 0;
     }
@@ -637,7 +637,7 @@ inline void make_env_var(StringArray &env, StringBuffer &var, const char *name,
     env.append(var.clear().append(name).append('=').append(value).str());
 }
 
-inline void make_env_var(StringArray &env, StringBuffer &var, const char *name, int value)
+inline void make_env_var(StringArray &env, StringBuffer &var, const char *name, __int64 value)
 {
     env.append(var.clear().append(name).append('=').append(value).str());
 }

+ 12 - 19
esp/bindings/http/platform/httptransport.cpp

@@ -322,7 +322,6 @@ CHttpMessage::CHttpMessage(ISocket& socket) : m_socket(socket)
 {
     m_bufferedsocket.setown(createBufferedSocket(&socket));
     m_content_length = -1;
-    m_content_length64 = -1;
     m_port = 80;
     m_paramCount = 0;
     m_attachCount = 0;
@@ -376,10 +375,7 @@ int CHttpMessage::parseOneHeader(char* oneline)
     else if(!stricmp(name, "Content-Length"))
     {
         if(value != NULL)
-        {
-            m_content_length = atoi(value);
-            m_content_length64 = atoi64_l(value,strlen(value));
-        }
+            m_content_length = atoi64_l(value,strlen(value));
     }
     else if(!stricmp(name, "Host"))
     {
@@ -525,9 +521,9 @@ int CHttpMessage::readContent()
 
     if(m_content_length > 0)
     {
-        int totallen = m_content_length;
+        __int64 totallen = m_content_length;
         if(buflen > totallen)
-            buflen = totallen;
+            buflen = (int)totallen;
         int readlen = 0;    
         for(;;)
         {
@@ -545,7 +541,7 @@ int CHttpMessage::readContent()
             if(totallen <= 0)
                 break;
             if(buflen > totallen)
-                buflen = totallen;
+                buflen = (int)totallen;
         }
         
         return 0;
@@ -609,7 +605,7 @@ int CHttpMessage::receive(bool alwaysReadContent, IMultiException *me)
         return -1;
 
     if (getEspLogLevel()>LogNormal)
-        DBGLOG("Headers processed! content_length = %d", m_content_length);
+        DBGLOG("Headers processed! content_length = %"I64F"d", m_content_length);
     
     if (isUpload())
         return 0;
@@ -672,8 +668,7 @@ void CHttpMessage::setContent(IFileIOStream* stream)
     if(stream != NULL)
     {
         m_content.clear();
-        m_content_length = (int)stream->size();
-        m_content_length64 = stream->size();
+        m_content_length = stream->size();
         m_content_stream.setown(stream);
     }
 }
@@ -822,12 +817,10 @@ int CHttpMessage::send()
     }
 
     // When m_content is empty but the stream was set, read content from the stream.
-    if(((m_content_length > 0 && m_content.length() == 0) || (m_content_length64 > 0)) && m_content_stream.get() != NULL)
+    if((m_content_length > 0 && m_content.length() == 0) && m_content_stream.get() != NULL)
     {
         //Read the file and send out 20K at a time.
         __int64 content_length = m_content_length;
-        if ((m_content_length64 > 0) && (content_length != m_content_length64))
-            content_length = m_content_length64;
         int buflen = 20*1024;
         if(buflen > content_length)
             buflen = (int) content_length;
@@ -1766,7 +1759,7 @@ StringBuffer& CHttpRequest::constructHeaderBuffer(StringBuffer& headerbuf, bool
 
     headerbuf.append("\r\n");
 
-    if(inclLength && m_content_length > 0) 
+    if(inclLength && m_content_length > 0)
         headerbuf.append("Content-Length: ").append(m_content_length).append("\r\n");
 
     if(m_cookies.length() > 0)
@@ -1895,7 +1888,7 @@ void CHttpRequest::readUploadFileContent(StringArray& fileNames, StringArray& fi
     multipart->parseContentType(m_content_type.get());
 
     MemoryBuffer fileContent, moreContent;
-    __int64 bytesNotRead = m_content_length64;
+    __int64 bytesNotRead = m_content_length;
     while (1)
     {
         StringBuffer fileName, content;
@@ -1940,7 +1933,7 @@ int CHttpRequest::readContentToFiles(StringBuffer netAddress, StringBuffer path,
     multipart->parseContentType(contentType);
 
     MemoryBuffer fileContent, moreContent;
-    __int64 bytesNotRead = m_content_length64;
+    __int64 bytesNotRead = m_content_length;
     while (1)
     {
         StringBuffer fileName;
@@ -2053,7 +2046,7 @@ StringBuffer& CHttpResponse::constructHeaderBuffer(StringBuffer& headerbuf, bool
         headerbuf.append("text/xml; charset=UTF-8");
     headerbuf.append("\r\n");
 
-    if(inclLen && m_content_length > 0) 
+    if(inclLen && m_content_length > 0)
         headerbuf.append("Content-Length: ").append(m_content_length).append("\r\n");
 
     headerbuf.append("Connection: close\r\n");
@@ -2331,7 +2324,7 @@ int CHttpResponse::receive(bool alwaysReadContent, IMultiException *me)
         return -1;
 
     if (getEspLogLevel()>LogNormal)
-        DBGLOG("Response headers processed! content_length = %d", m_content_length);
+        DBGLOG("Response headers processed! content_length = %"I64F"d", m_content_length);
     
     char status_class = '2';
     if(m_status.length() > 0)

+ 3 - 4
esp/bindings/http/platform/httptransport.ipp

@@ -54,8 +54,7 @@ protected:
     Owned<IBufferedSocket> m_bufferedsocket;
 
     StringAttr   m_content_type;
-    int          m_content_length;
-    __int64      m_content_length64;
+    __int64      m_content_length;
     StringBuffer m_content;
     StringBuffer m_header;
     OwnedIFileIOStream m_content_stream;
@@ -107,7 +106,7 @@ public:
     virtual int close();
 
     virtual bool supportClientXslt();
-    unsigned getContentLength(){return m_content_length;}
+    __int64 getContentLength(){return m_content_length;}
     const char *queryContent(){return m_content.str();}
     const char *queryHeader() { return m_header.str(); }
     void logSOAPMessage(const char* message, const char* prefix = NULL);
@@ -166,7 +165,7 @@ public:
         if (type==NULL || *type==0)
             return (m_content_type.length()==0);
 
-        return ( (m_content_length > 0 || m_content_length64 > 0 || Utils::strncasecmp(HTTP_TYPE_FORM_ENCODED,type,sizeof(HTTP_TYPE_FORM_ENCODED)-1)==0)
+        return ( (m_content_length > 0 || Utils::strncasecmp(HTTP_TYPE_FORM_ENCODED,type,sizeof(HTTP_TYPE_FORM_ENCODED)-1)==0)
             && Utils::strncasecmp(m_content_type.get(), type, strlen(type)) == 0);
     }
 

+ 5 - 5
esp/bindings/http/platform/mime.cpp

@@ -250,7 +250,7 @@ void CMimeMultiPart::serialize(StringBuffer& contenttype, StringBuffer & buffer)
     }
 }
 
-void CMimeMultiPart::unserialize(const char* contenttype, int text_length, const char* text)
+void CMimeMultiPart::unserialize(const char* contenttype, __int64 text_length, const char* text)
 {
     char* typebuf = new char[strlen(contenttype) + 1];
     strcpy(typebuf, contenttype);
@@ -315,8 +315,8 @@ void CMimeMultiPart::unserialize(const char* contenttype, int text_length, const
     delete [] typebuf;
 
     int oneline_len = 0;
-    int cur_pos = 0;
-    int next_pos = Utils::getLine(text_length, 0, text, oneline_len);
+    __int64 cur_pos = 0;
+    __int64 next_pos = Utils::getLine(text_length, cur_pos, text, oneline_len);
     const char* curline = text;
     int boundarylen = m_boundary.length();
 
@@ -399,7 +399,7 @@ void CMimeMultiPart::unserialize(const char* contenttype, int text_length, const
 
         // Read in the content of one mime part
         cur_pos = next_pos;
-        int bb = cur_pos;
+        __int64 bb = cur_pos;
         next_pos = Utils::getLine(text_length, next_pos, text, oneline_len);
         const char* curline = text + cur_pos;
         while(next_pos < text_length && !(oneline_len >= 2 && !Utils::strncasecmp(m_boundary.get(), curline + 2, boundarylen)))
@@ -410,7 +410,7 @@ void CMimeMultiPart::unserialize(const char* contenttype, int text_length, const
         }
 
         // Get rid of CR/LF at the end of the content
-        int be = cur_pos - 1;
+        __int64 be = cur_pos - 1;
         if(be >0 && (text[be] == '\r' || text[be] == '\n'))
             be--;
 

+ 1 - 1
esp/bindings/http/platform/mime.hpp

@@ -80,7 +80,7 @@ public:
     void readUploadFileName(MemoryBuffer& fileContent, StringBuffer& fileName);
 
     void serialize(StringBuffer& contenttype, StringBuffer & buffer);
-    void unserialize(const char* contenttype, int text_length, const char* text);
+    void unserialize(const char* contenttype, __int64 text_length, const char* text);
 };
 
 #endif

+ 1 - 1
esp/platform/espcontext.cpp

@@ -418,7 +418,7 @@ public:
         m_traceValues.append(str.str());
     }
 
-    virtual void addTraceSummaryValue(const char *name, int value)
+    virtual void addTraceSummaryValue(const char *name, __int64 value)
     {
         StringBuffer str;
         if (name && *name)

+ 1 - 1
esp/scm/esp.ecm

@@ -145,7 +145,7 @@ interface IEspContext : extends IInterface
     virtual void addCustomerHeader(const char* name, const char* val) = 0;
 
     virtual void addTraceSummaryValue(const char *name, const char *value)=0;
-    virtual void addTraceSummaryValue(const char *name, int value)=0;
+    virtual void addTraceSummaryValue(const char *name, __int64 value)=0;
     virtual void addTraceSummaryTimeStamp(const char *name)=0;
     virtual void flushTraceSummary()=0;