Chunked Transfer Encoding

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. For more information about chunked transfer encoding, and HTTP 1.1 in general, see section 3.6 of RFC 2068 at http://www.w3.org.

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.

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 sample is provided for educational purposes only. It has not been tested in a production environment, and Microsoft® will not provide technical support for it.

This project is available in the ...\iissamples\sdk\isapi\extensions\chunk subdirectory of the Internet services directory.


© 1997 by Microsoft Corporation. All rights reserved.