HOWTO: Prevent MFC ISAPI Extensions from Returning a Default Set of HeadersID: Q238554
|
Unexpected behavior may occur when sending headers from an MFC ISAPI extension. This may be due to the ISAPI Extension sending multiple sets of headers. You can avoid this problem by setting the m_bSendHeaders flag to false in the ISAPI request handler.
The following code will return a "302 object moved" response to a client:
void CSendURLExtension::Default(CHttpServerContext* pCtxt)
{
char szUrl[] = "http://server/test/ok.htm";
DWORD dwUrlSize = sizeof(szUrl);
pCtxt->ServerSupportFunction(HSE_REQ_SEND_URL, (void*)szUrl,
&dwUrlSize, NULL);
}
Most Internet browsers react to a 302 response by automatically requesting a the new URL. In the code above, however, some browsers respond with a "400 Bad Request" error.
(not all headers are shown)
Client request resource:
HTTP: GET Request (from client using port 1524)
HTTP: Request Method = GET
HTTP: Uniform Resource Identifier = /isapi/SendURL.dll?<BR/>
HTTP: Protocol Version = HTTP/1.1
HTTP: Host = uncle
HTTP: Connection = Keep-Alive
Server responds:
HTTP: Response (to client using port 1524)
HTTP: Protocol Version = HTTP/1.1
HTTP: Status Code = Found
HTTP: Reason = Object Moved
HTTP: Undocumented Header = Location: /ok.htm
Server also responds:
HTTP: Response (to client using port 1524)
HTTP: Protocol Version = HTTP/1.1
HTTP: Status Code = OK
HTTP: Reason = OK
HTTP: Connection = close
This response sequence is invalid. The server is sending a "302 object moved" response followed by a "200 OK" response. The client in this case responds to the 302 not expecting another response. The second response contains notification to the client that the connection has been closed. The client, unaware of this, requests the new page over a connection that has been closed and an error occurs. Please note that client ports may vary and 1524 is used as a sample.
void CSendURLExtension::Default(CHttpServerContext* pCtxt)
{
pCtxt->m_bSendHeaders = FALSE;
char szUrl[] = "http://server/test/ok.htm";
DWORD dwUrlSize = sizeof(szUrl);
pCtxt->ServerSupportFunction(HSE_REQ_SEND_URL, (void*)szUrl,
&dwUrlSize, NULL);
}
Q148942 How to Capture Network Traffic with Network Monitor
Q152643 Netmon Does Not Capture Outbound Frames
Additional query words:
Keywords : kbGrpInetServer kbDSupport
Version :
Platform :
Issue type : kbhowto
Last Reviewed: August 9, 1999