BUG: WinCE Web Server Adds Extra CRLF to HTTP Headers Using HSE_REQ_SEND_RESPONSE_HEADER (290392)



The information in this article applies to:

  • Microsoft Windows CE Operating System, Versions 3.0

This article was previously published under Q290392

SYMPTOMS

When an Internet Server API (ISAPI) extension adds custom HTTP headers to a response through the ServerSupportFunction(HSE_REQ_SEND_RESPONSE_HEADER,.) callback, the data that the ISAPI sends is garbled by the client. This may be manifested in HTML not being rendering correctly or images not displaying. This is likely to occur on ISAPI extensions that are ported from Internet Information Server (IIS).

CAUSE

The problem is caused by a difference between how IIS and the Windows CE Web Server handle ServerSupportFunction with option HSE_REQ_SEND_RESPONSE_HEADER when extra headers are being used (passed in the fifth function parameter lpdwDataType). On IIS, it is the ISAPI's responsibility to append a double CRLF to the end of the string to signify the end of the HTTP headers. The Windows CE Web Server appends a CRLF automatically when extra headers are used, regardless of what the ISAPI extension passed in.

A double CRLF signifies the end of the HTTP headers and the beginning of the HTTP body. If an ISAPI extension uses the IIS convention of adding two CRLFs to the end of the header string, then the browser treats the first two bytes after the CRLFs (the single CRLF that the Web Server added) as the first bytes of the HTTP body, causing the error.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The way to work around this problem is to terminate the extra headers with only one CRLF for versions of the Web Server on Windows CE 3.0. The Web Server will then tack on the second CRLF to the end of the response, which will produce the desired result.
The following pseudo-code demonstrates the way to work around this problem:
#if defined (UNDER_CE)
#include <bldver.h>  
#endif


#if defined (UNDER_CE) && (CE_MAJOR_VER < 4)
#define CLOSING_CRLF                      // empty, web server adds extra CRLF
#else
#define CLOSING_CRLF  "\r\n"         // on IIS and CE 4.0, ISAPI must do this.
#endif

CHAR szHeaders[] = "extra-header1: data1\r\r"
                   "extra-header1: data2\r\n" CLOSING_CRLF;  

DWORD HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK pECB) {
	// 
	// do processing.
	// 
         pECB->ServerSupportFunction(pECB->ConnID,  
                HSE_REQ_SEND_RESPONSE_HEADER,0,0,(DWORD*)szHeaders);

	// rest of processing.
}
				

Steps to Reproduce Behavior

On a Windows CE 3.0 device, create a simple IIS-compatible ISAPI extension, send custom headers across using ServerSupportFunction with the HSE_REQ_SEND_RESPONSE_HEADER flag, and then send data using WriteClient. When you view the source in the browser, the first two characters that appear are the CRLFs that the Web Server erroneously added to the end of the request.

Modification Type:MinorLast Reviewed:12/27/2003
Keywords:kbbug KB290392