How to remove headers in an ISAPI filter?

The ISAPI filter documentation states that I can call SF_REQ_SEND_RESPONSE_HEADER to send a response header, as well as add additional headers.

ISAPI also has AddResponseHeaders to allow the filter to add additional headers to be sent in response to the client.

Is there a way in ISAPI to remove headers that would otherwise be sent to the client? Or somehow ask the ISAPI runtime to exclude certain headers from the response? The ISAPI runtime always includes the Server header: and I would like to find a way to remove it.

I know that I can set or cancel headers administratively in IIS Manager, but this is not quite what I want. I want to do this at runtime in a filter, programmatically and conditionally.

EDIT: BUMP.

+3
source share
2 answers

I wrote several ISAPIs, including one that had the functionality that you describe. I used SF_NOTIFY_SEND_RAW_DATA - I believe that the first call will be the header, so you can use:

FilterContext-> ServerSupportFunction (FilterContext, SF_REQ_DISABLE_NOTIFICATIONS, 0, SF_NOTIFY_SEND_RAW_DATA, 0);

. HTTP_FILTER_RAW_DATA pvInData, , , HTTP_FILTER_RAW_DATA, ( FilterContext- > AllocMem pvInData). , FilterContext- > WriteClient SF_STATUS_REQ_READ_NEXT.

, SF_NOTIFY_ORDER_HIGH SF_NOTIFY_SEND_RAW_DATA.

, , , ( ), , , , . , , , -, RAW_DATA IIS5 ( ), IIS6 +, ISAPI, , , . , , , , , , !:)

+2

(Firefor HTML b/c )

DWORD CMyAuthFilterImpl::OnSendRawData(PHTTP_FILTER_CONTEXT pfc, DWORD NotoficationType, LPVOID pvNotification)
{
SF_STATUS_TYPE retStatus =  SF_STATUS_REQ_NEXT_NOTIFICATION;

if(m_bWriteHeader)
{
    //rewriting response headers with correct information
    pfc->ServerSupportFunction(pfc, SF_REQ_DISABLE_NOTIFICATIONS, 0, SF_NOTIFY_SEND_RAW_DATA, 0);

    PHTTP_FILTER_RAW_DATA pSD = (PHTTP_FILTER_RAW_DATA)pvNotification;
    DWORD dL = (DWORD)m_pszHeaders.length();
    pSD->pvInData = pfc->AllocMem(pfc, dL, 0);

    memcpy(pSD->pvInData, (void*)m_pszHeaders.data(), dL);
    pSD->cbInData = dL;

    m_bWriteHeader=FALSE;

    m_dwordHeaderLength=0;
    m_pszHeaders.~basic_string();
    retStatus =  SF_STATUS_REQ_NEXT_NOTIFICATION;

}


return retStatus;
}
+1

Source: https://habr.com/ru/post/1712817/


All Articles