tags:

views:

292

answers:

1

The ISAPI Filter documentation says I can call SF_REQ_SEND_RESPONSE_HEADER to send the response header, and also append additional headers.

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

Is there a way, in ISAPI, to remove headers that would otherwise be sent to the client? Or some way to ask the ISAPI runtime to exclude certain headers from the response? The ISAPI runtime seems to always include a Server: header, and I'd like to find a way to remove that.

I know I can set or unset headers administratively, in the IIS Manager, but that isn't quite what I want. I want to do it at runtime in the filter, programmatically, and conditionally.

EDIT: BUMP.

+1  A: 

I've written several ISAPI's, including one that had the functionality you describe. I used SF_NOTIFY_SEND_RAW_DATA - I believe 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);

to disable notifications for future raw data. Then in the HTTP_FILTER_RAW_DATA structure you've got pvInData, which is the current header, I read in and then write it into a new HTTP_FILTER_RAW_DATA I allocated (remember to use FilterContext->AllocMem for both the structure and pvInData). Once you're done, write the new header out FilterContext->WriteClient and return SF_STATUS_REQ_READ_NEXT.

Also, on initialization make sure to set SF_NOTIFY_ORDER_HIGH and SF_NOTIFY_SEND_RAW_DATA.

From looking through my old code, that's what I did and it was to specifically remove a header (plus it also added one), so it certainly will perform what you need to do. The only caveat I will say is that I remember something changing related to RAW_DATA from IIS5 (when I wrote this) to IIS6+, but I never needed to update this particular ISAPI, so I don't know if a chance effected how it's done or not. Hopefully this helps you out, although you probably at least got a tumbleweed for your question! :)

Mark
Great, thanks. A good idea. I'll give it a try.
Cheeso