@@ -153,7 +153,7 @@ result_t HttpMessage::readFrom(Stream_base* stm, AsyncEvent* ac)
153153            : AsyncState(ac)
154154            , m_pThis(pThis)
155155            , m_stm(stm)
156-             , m_contentLength(0 )
156+             , m_contentLength(- 1 )
157157            , m_bChunked(false )
158158            , m_headCount(0 )
159159        {
@@ -173,7 +173,7 @@ result_t HttpMessage::readFrom(Stream_base* stm, AsyncEvent* ac)
173173
174174                    if  ((m_contentLength < 0 )
175175                        || (m_pThis->m_maxBodySize  >= 0 
176-                                 && m_contentLength > m_pThis->m_maxBodySize  * 1024  * 1024 ))
176+                             && m_contentLength > m_pThis->m_maxBodySize  * 1024  * 1024 ))
177177                        return  CHECK_ERROR (Runtime::setError (" HttpMessage: body is too huge."  ));
178178                } else  if  (!qstricmp (m_strLine.c_str (),
179179                               " transfer-encoding:"  , 18 )) {
@@ -202,14 +202,15 @@ result_t HttpMessage::readFrom(Stream_base* stm, AsyncEvent* ac)
202202                if  (m_pThis->m_maxBodySize  == 0 )
203203                    return  next ();
204204
205-                 if  (m_contentLength)
205+                 if  (m_contentLength >  0 )
206206                    return  CHECK_ERROR (CALL_E_INVALID_DATA);
207+                 m_contentLength = 0 ;
207208
208209                m_pThis->get_body (m_body);
209210                return  next (chunk_head);
210211            }
211212
212-             if  (!m_pThis->m_bNoBody  && m_contentLength > 0 ) {
213+             if  (!m_pThis->m_bNoBody  && ( m_contentLength > 0  || (m_pThis-> m_bResponse  && !m_pThis-> m_keepAlive  && m_contentLength == - 1 )) ) {
213214                m_pThis->get_body (m_body);
214215                return  m_stm->copyTo (m_body, m_contentLength, m_copySize, next (body));
215216            }
@@ -219,7 +220,7 @@ result_t HttpMessage::readFrom(Stream_base* stm, AsyncEvent* ac)
219220
220221        ON_STATE (asyncReadFrom, body)
221222        {
222-             if  (!m_pThis->m_bNoBody  && m_contentLength != m_copySize)
223+             if  (!m_pThis->m_bNoBody  && m_contentLength >  0  && m_contentLength  != m_copySize)
223224                return  CHECK_ERROR (Runtime::setError (" HttpMessage: body is not complete."  ));
224225
225226            m_body->rewind ();
0 commit comments