Adding to a Response Header

One use of ISAPI filters is to modify a response header before IIS sends it to the client. For example, you might want to modify the expires value. The following code illustrates how to accomplish this.

BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
    pVer->dwFilterVersion = HTTP_FILTER_REVISION;
    lstrcpy(pVer->lpszFilterDesc, "Filter Template");
    pVer->dwFlags = SF_NOTIFY_ORDER_DEFAULT | SF_NOTIFY_URL_MAP;

    return TRUE;
}

DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD NotificationType, LPVOID pvNotification)
{
    HTTP_FILTER_URL_MAP *pUrlMap = (HTTP_FILTER_URL_MAP *)pvNotification;
    LPSTR szPtr1;

    // Find the extension of the requested file
    szPtr1 = strrchr(pUrlMap->pszPhysicalPath, '.');

    // If this is a JPG, add an expires header
    if (szPtr1)
    {
        szPtr1++;
        if (!lstrcmpi(szPtr1, "jpg"))
            pfc->AddResponseHeaders(pfc, "Expires: 0\r\n", 0);
    }
    
    return SF_STATUS_REQ_NEXT_NOTIFICATION;
}
 

For a complete working sample program that modifies a response header, see Developer Samples.