[prev in list] [next in list] [prev in thread] [next in thread]
List: helix-filesystem-cvs
Subject: [Filesystem-cvs] http httpfsys.cpp,1.63,1.64 httpfsys.h,1.21,1.22
From: bobclark () helixcommunity ! org
Date: 2004-12-08 3:04:52
[Download RAW message or body]
Update of /cvsroot/filesystem/http
In directory cvs-new:/tmp/cvs-serv8317
Modified Files:
httpfsys.cpp httpfsys.h
Log Message:
some consolidation of redundant code; also allow http content that is both \
Transfer-Encoding: chunked and Content-Encoding: gzip to work. bug 121586. cr gwright
Index: httpfsys.h
===================================================================
RCS file: /cvsroot/filesystem/http/httpfsys.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- httpfsys.h 16 Nov 2004 17:50:39 -0000 1.21
+++ httpfsys.h 8 Dec 2004 03:04:50 -0000 1.22
@@ -667,6 +667,8 @@
void ReportDocumentMissing ();
void ReportGeneralFailure ();
+ HX_RESULT _SetDataJustDownloaded(const char* pRawBuf, UINT32 ulLength);
+ HX_RESULT _SetDataGzipEncoded(const char* pRawBuf, UINT32 ulLength);
HX_RESULT DecodeChunkedEncoding(HTTPChunkedEncoding*& pChunkedEncoding,
const char* pChunk,
int l);
Index: httpfsys.cpp
===================================================================
RCS file: /cvsroot/filesystem/http/httpfsys.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- httpfsys.cpp 1 Dec 2004 19:50:18 -0000 1.63
+++ httpfsys.cpp 8 Dec 2004 03:04:49 -0000 1.64
@@ -3388,7 +3388,9 @@
}
// Tell the server that we support encoded content
+#if defined(HELIX_FEATURE_HTTP_GZIP)
m_strRequest += szAcceptEncoding;
+#endif
if (m_bByteRangeSeekPending)
{
@@ -5096,52 +5098,8 @@
INT32 nContentLen = pBuffer->GetSize() - ulHeaderLength;
if (nContentLen > 0)
{
- if (m_bEncoded)
- {
-#if defined(HELIX_FEATURE_HTTP_GZIP)
- theErr = m_pDecoder->SetData(0,
- (const char*)pBuffer->GetBuffer() + ulHeaderLength,
- nContentLen);
- m_nContentRead = m_pDecoder->GetContentRead();
-
- if (FAILED(theErr))
- {
- // A failure occurred while trying to decode
- // the data, so we must quit
- SetReadContentsDone(TRUE);
- }
-#else
- /* We have gzip-encoded data, but do not have
- gzip support compiled in, so we must fail. */
- theErr = HXR_FAIL;
- SetReadContentsDone(TRUE);
-#endif /* #if defined(HELIX_FEATURE_HTTP_GZIP) */
- }
- else if (m_bChunkedEncoding)
- {
- m_pChunkedEncoding = new HTTPChunkedEncoding;
- m_pChunkedEncoding->size = 0;
- m_pChunkedEncoding->read = 0;
- m_pChunkedEncoding->lastchunk = FALSE;
- m_pChunkedEncoding->state = CE_HEADER_PENDING;
- m_pChunkedEncoding->buf = new char[MAX_CHUNK_SIZE];
-
- DecodeChunkedEncoding(m_pChunkedEncoding,
- (const char*)pBuffer->GetBuffer() + ulHeaderLength,
- nContentLen);
- }
- else
- {
- HXLOGL3(HXLOG_HTTP,
- "Network: _HandleSuccess, WriteChunky at %ld size %ld",
- m_nContentRead, nContentLen);
-
- m_pChunkyRes->SetData(m_nContentRead,
- (const char*)pBuffer->GetBuffer() + ulHeaderLength,
- nContentLen, this);
- m_nContentRead += nContentLen;
-
- }
+ _SetDataJustDownloaded((const char*)pBuffer->GetBuffer() + \
ulHeaderLength, + nContentLen);
}
// See if the data trailing after the header contains all
@@ -7466,55 +7424,7 @@
// end of the results buffer.
if (m_bReadHeaderDone)
{
- if (m_bEncoded)
- {
-#if defined(HELIX_FEATURE_HTTP_GZIP)
- retVal = m_pDecoder->SetData(m_nContentRead,
- (char*) pBuffer->GetBuffer(),
- ulSize);
- m_nContentRead = m_pDecoder->GetContentRead();
- if (FAILED(retVal))
- {
- // A failure occurred while trying to decode
- // the data, so we must quit
- SetReadContentsDone(TRUE);
- }
-#else /* #if defined(HELIX_FEATURE_HTTP_GZIP) */
- /* We have gzip-encoded data, but do not have
- gzip support compiled in, so we must fail. */
- retVal = HXR_FAIL;
- SetReadContentsDone(TRUE);
-#endif /* #if defined(HELIX_FEATURE_HTTP_GZIP) */
- }
- else if (m_bChunkedEncoding)
- {
- HX_ASSERT(m_pChunkedEncoding);
- if (!m_pChunkedEncoding)
- {
- m_pChunkedEncoding = new HTTPChunkedEncoding;
- m_pChunkedEncoding->size = 0;
- m_pChunkedEncoding->read = 0;
- m_pChunkedEncoding->lastchunk = FALSE;
- m_pChunkedEncoding->state = CE_HEADER_PENDING;
- m_pChunkedEncoding->buf = new char[MAX_CHUNK_SIZE];
- }
-
- DecodeChunkedEncoding(m_pChunkedEncoding,
- (const char*)pBuffer->GetBuffer(),
- ulSize);
- }
- else
- {
- HXLOGL4(HXLOG_HTTP,
- "Network: HandleSocketRead WriteChunky at %ld size %ld",
- m_nContentRead, ulSize);
-
- m_pChunkyRes->SetData(m_nContentRead,
- (char*) pBuffer->GetBuffer(),
- ulSize,
- this);
- m_nContentRead += ulSize;
- }
+ _SetDataJustDownloaded((const char*)pBuffer->GetBuffer(), ulSize);
if (m_bKnowContentSize && m_nContentRead >= m_nContentSize)
{
@@ -8209,6 +8119,72 @@
}
}
+
+// consolidated from a couple places (HandleSocketRead and HandleSuccess)
+// that both perform an identical task...
+
+HX_RESULT
+CHTTPFileObject::_SetDataJustDownloaded(const char* pRawBuf, UINT32 ulLength)
+{
+ HX_RESULT theErr = HXR_OK;
+
+ // first check for chunked-encoding, THEN check for gzip encoding. If
+ // content is both gzip-encoded AND chunked, then it must be de-chunked
+ // before it's ungzipped.
+
+ if (m_bChunkedEncoding)
+ {
+ if (!m_pChunkedEncoding)
+ {
+ m_pChunkedEncoding = new HTTPChunkedEncoding;
+ m_pChunkedEncoding->size = 0;
+ m_pChunkedEncoding->read = 0;
+ m_pChunkedEncoding->lastchunk = FALSE;
+ m_pChunkedEncoding->state = CE_HEADER_PENDING;
+ m_pChunkedEncoding->buf = new char[MAX_CHUNK_SIZE];
+ }
+
+ DecodeChunkedEncoding(m_pChunkedEncoding, pRawBuf, ulLength);
+ }
+ else if (m_bEncoded)
+ {
+ theErr = _SetDataGzipEncoded(pRawBuf, ulLength);
+ }
+ else
+ {
+ // plain old vanilla http content, non-chunked, non-gzipped.
+ HXLOGL4(HXLOG_HTTP,
+ "Network: _SetDataJustDownloaded WriteChunky at %ld size %ld",
+ m_nContentRead, ulLength);
+ m_pChunkyRes->SetData(m_nContentRead, pRawBuf, ulLength, this);
+ m_nContentRead += ulLength;
+ }
+ return theErr;
+}
+
+HX_RESULT
+CHTTPFileObject::_SetDataGzipEncoded(const char* pRawBuf, UINT32 ulLength)
+{
+ HX_RESULT theErr = HXR_OK;
+
+ HX_ASSERT(m_pDecoder);
+
+#if defined(HELIX_FEATURE_HTTP_GZIP)
+ theErr = m_pDecoder->SetData(m_nContentRead, pRawBuf, ulLength);
+ m_nContentRead = m_pDecoder->GetContentRead();
+ if (FAILED(theErr))
+ {
+ SetReadContentsDone(TRUE);
+ }
+#else
+ HXLOGL1(HXLOG_HTTP, "gzip content found when we didn't request it!");
+ theErr = HXR_FAIL;
+ SetReadContentsDone(TRUE);
+#endif
+
+ return theErr;
+}
+
HX_RESULT
CHTTPFileObject::DecodeChunkedEncoding(HTTPChunkedEncoding*& pChunkedEncoding,
const char* pChunk,
@@ -8263,11 +8239,24 @@
break;
}
- HXLOGL4(HXLOG_HTTP, "Encoding: WriteChunky at %ld size %ld",
- m_nContentRead, pChunkedEncoding->size);
+ if (m_bEncoded)
+ {
+ // it's kind of an odd thing, but here we are processing
+ // content that is both chunked and gzip encoded. The only
+ // place I've seen this in the wild is at shoutcast.com, and
+ // then I've never seen more than one chunk.
- m_pChunkyRes->SetData(m_nContentRead, pChunkedEncoding->buf, \
pChunkedEncoding->size, this);
- m_nContentRead += pChunkedEncoding->size;
+ // SetDataGzipEncoded will update m_nContentRead
+ rc = _SetDataGzipEncoded(pChunkedEncoding->buf, \
pChunkedEncoding->size); + }
+ else
+ {
+ HXLOGL4(HXLOG_HTTP, "Encoding: WriteChunky at %ld size %ld",
+ m_nContentRead, pChunkedEncoding->size);
+
+ m_pChunkyRes->SetData(m_nContentRead, pChunkedEncoding->buf, \
pChunkedEncoding->size, this); + m_nContentRead += \
pChunkedEncoding->size; + }
memset(pChunkedEncoding->buf, 0, MAX_CHUNK_SIZE);
pChunkedEncoding->read = 0;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic