Microsoft KB Archive/290392

= BUG: WinCE Web Server Adds Extra CRLF to HTTP Headers Using HSE_REQ_SEND_RESPONSE_HEADER =

Article ID: 290392

Article Last Modified on 12/27/2003

-

APPLIES TO


 * Microsoft Windows CE 3.0 for the Handheld PC

-



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:
 * 1) if defined (UNDER_CE)
 * 2) include 
 * 3) endif


 * 1) if defined (UNDER_CE) && (CE_MAJOR_VER < 4)
 * 2) define CLOSING_CRLF                     // empty, web server adds extra CRLF
 * 3) else
 * 4) define CLOSING_CRLF &quot;\r\n&quot;         // on IIS and CE 4.0, ISAPI must do this.
 * 5) endif

CHAR szHeaders[] = &quot;extra-header1: data1\r\r&quot; &quot;extra-header1: data2\r\n&quot; 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.

Keywords: kbbug KB290392

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.