Sending a Header

Before your extension delivers any output, it must send the client an HTTP response header. This header must be in the correct format or the client will not be able to use it. Among other things, the response header specifies the type of content that you are returning to the client and whether or not the connection should be kept active after the request has been serviced.

To send a response header you should call the ServerSupportFunction (HSE_REQ_SEND_RESPONSE_HEADER_EX). (Note that HSE_REQ_SEND_RESPONSE_HEADER_EX is an upgrade from the HSE_REQ_SEND_RESPONSE_HEADER function.)This function uses the HSE_SEND_HEADER_EX_INFO structure to specify the header information. The processing steps you should build into your extension in order to send a response header are:

The following example demonstrates using the ServerSupportFunction (HSE_REQ_SEND_RESPONSE_HEADER_EX) to send a response header.

*/
GetExtensionVersion

IIS calls this entry point to load the ISAPI DLL.

Returns:
    TRUE on success

Side effects:
    None.
*/
BOOL WINAPI
GetExtensionVersion(
    HSE_VERSION_INFO *pVer
)
{
    pVer->dwExtensionVersion =
        MAKELONG( HSE_VERSION_MINOR, HSE_VERSION_MAJOR );

    lstrcpyn(
        pVer->lpszExtensionDesc
        , "ISAPI SendHeaderEx sample"
        , HSE_MAX_EXT_DLL_NAME_LEN
    );

    return TRUE;
}



/*---------------------------------------------------------------------*
HttpExtensionProc

IIS calls this entry point to process a browser request.

Returns:
    TRUE on success

Side effects:
    None.
*/
DWORD WINAPI
HttpExtensionProc(
    EXTENSION_CONTROL_BLOCK *pECB
)
{

    HSE_SEND_HEADER_EX_INFO    SendHeaderExInfo;

    DWORD cchStatus;
    DWORD cchHeader;
    DWORD cchContent;

    //
    //  NOTE we must send Content-Length header with correct byte count
    //  in order for keep-alive to work.
    //

    char szStatus[]     = "200 OK";
    char szContent[]    =   "<html>"
                            "<br> Usage:"
                            "<br> To keep connection alive: http://localhost/vdir/SendHdrX.dll?Keep-Alive"
                            "<br> To close connection: http://localhost/vdir/SendHdrX.dll"
                            "</html>";
    char szHeaderBase[] = "Content-Length: %lu\r\nContent-type: text/html\r\n\r\n";
    char szHeader[4096];

    cchStatus = lstrlen(szStatus);
    cchHeader = lstrlen(szHeader);
    cchContent = lstrlen(szContent);
    
    //
    //  fill in byte count in Content-Length header
    //

    sprintf( szHeader, szHeaderBase, cchContent );

    //
    //  Populate SendHeaderExInfo struct
    //

    SendHeaderExInfo.pszStatus = szStatus;
    SendHeaderExInfo.pszHeader = szHeader;
    SendHeaderExInfo.cchStatus = cchStatus;
    SendHeaderExInfo.cchHeader = cchHeader;
    SendHeaderExInfo.fKeepConn = FALSE;

    if ( 0 == lstrcmpi( pECB->lpszQueryString , "Keep-Alive" ) ) {

        SendHeaderExInfo.fKeepConn = TRUE;
    }

    //
    //  Send header
    //

    if ( !pECB->ServerSupportFunction(
                pECB->ConnID
                , HSE_REQ_SEND_RESPONSE_HEADER_EX
                , &SendHeaderExInfo
                , NULL
                , NULL
            ) ) {

        return HSE_STATUS_ERROR;
}

For a complete working sample of an extension that sends a response header to the client, see Developer Samples.


© 1997 by Microsoft Corporation. All rights reserved.