This sample demonstrates how you can use HTTP 1.1 chunked transfer-encoding in your own ISAPI extension. Chunked transfer encoding enables the sender, whether it be IIS or an ISAPI extension, to transfer the body of an HTTP message in a series of chunks, each with its own size indicator. Since message content is transferred along with the information necessary for the recipient to verify that it has received the complete message, chunked transfer encoding enables your ISAPI extension to send dynamically-created messages without pre-calculating the message length.
This sample implements a simple extension that demonstrates chunked transfer encoding. Once the project has been compiled and the DLL created, the extension can be accessed. A query string is appended to the URL, specifying the file that should be sent and the chunk size to use in the chunked transfer. Thus the URL http://www.mysite.com/ctetest.dll?file=/sample.gif&chunksize=1024 indicates that the extension should send the file sample.gif, located in the virtual root directory of the Web site, to your client browser, using chunked transfer encoding and a chunk size of 1024 bytes.
The project file ctetest.c implements the main ISAPI entry-point functions GetExtensionVersion and HttpExtensionProc, as well as various helper functions used to process the transfer request.
The bulk of the chunked transfer code is contained within the actual transfer functions, in the project file cte_enc.c. Three functions are provided in this file: CteBeginWrite, CteWrite, and CteEndWrite. These functions, though commented for educational value, were designed to be reusable, so if you need to create an extension that is HTTP 1.1-compliant, these functions may be called, in the obvious order, to accomplish the chunked transfer.
Any data in lpbBuffer should not contain the chunk encoding. Any data retrieved by ReadClient (or its async equivalent) should not contain the chunk encoding, and the value of dwSize on return from ReadClient (or in the IO completion function) should never include the size of the chunk encoding.
For more information about chunked transfer encoding, see section 3.6 of RFC 2068 at www.w3.org/.
Note To access this sample extension, you will need to use a client browser that supports HTTP 1.1, such as Microsoft® Internet Explorer® 4.0 or later.
This project is available in the ...\isapi\extensions\cgiwrap subdirectory of the IIS samples directory.