Search code examples
c++gzipzlibdeflate

how i can send gzip instade deflate by skip header


i write a c++ http server ( Microsoft http server api )

that send html page file in gzip format

and gzip file is static

for example file page1.htm and page1.htm.gz are in same directory

according to http://en.wikipedia.org/wiki/Gzip

i know that gzip is deflate with extra header and deflate is part of gzip

how i can sending gzip instade deflate by skip header

fileHandle=CreateFile( "page1.htm.gz"  ,dwAccess,dwShare,NULL,dwCreationFlags,dwAttributes,NULL);

....


ADD_KNOWN_HEADER(response, HttpHeaderContentEncoding, "deflate" );

HTTP_DATA_CHUNK dataChunk;
{     
   HTTP_DATA_CHUNK dataChunk;
   response.EntityChunkCount         = 1;                        
   dataChunk.DataChunkType           = HttpDataChunkFromFileHandle;
   dataChunk.FromFileHandle.FileHandle   =fileHandle;
   dataChunk.FromFileHandle.ByteRange.StartingOffset.QuadPart =9;// 9 is gzip header len
   dataChunk.FromFileHandle.ByteRange.Length.QuadPart = HTTP_BYTE_RANGE_TO_EOF;
   response.pEntityChunks=&dataChunk;
}     

 .....

Solution

  • The deflate and gzip encoding are not quite the same thing, although the differences are minor.

    When you are sending gzip, change your code to:

    ADD_KNOWN_HEADER(response, HttpHeaderContentEncoding, "gzip" );
    

    You should do that of course if gzip is listed in Accept-Encoding.

    Here's an excerpt from the gzip FAQ:

    “ What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?

    "gzip" is the gzip format, and "deflate" is the zlib format. They should probably have called the second one "zlib" instead to avoid confusion with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 correctly points to the zlib specification in RFC 1950 for the "deflate" transfer encoding, there have been reports of servers and browsers that incorrectly produce or expect raw deflate data per the deflate specficiation in RFC 1951, most notably Microsoft. So even though the "deflate" transfer encoding using the zlib format would be the more efficient approach (and in fact exactly what the zlib format was designed for), using the "gzip" transfer encoding is probably more reliable due to an unfortunate choice of name on the part of the HTTP 1.1 authors.”

    http://www.gzip.org/zlib/zlib_faq.html#faq38