如何删除 ISAPI 过滤器中的标头?
ISAPI 过滤器文档说我可以调用 SF_REQ_SEND_RESPONSE_HEADER 发送响应标头,并附加附加标头。
ISAPI 还具有 AddResponseHeaders 来允许过滤器添加其他 响应中发送给客户端的标头。
在 ISAPI 中,有没有办法删除否则会发送到客户端的标头? 或者通过某种方式要求 ISAPI 运行时从响应中排除某些标头? ISAPI 运行时似乎总是包含一个 Server: 标头,我想找到一种方法来删除它。
我知道我可以在 IIS 管理器中以管理方式设置或取消设置标头,但这并不是我想要的。 我想在运行时在过滤器中以编程方式和有条件地执行此操作。
编辑:碰撞。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经编写了几个 ISAPI,其中一个具有您所描述的功能。 我使用了 SF_NOTIFY_SEND_RAW_DATA - 我相信第一个调用将是标头,因此您可以使用:
FilterContext->ServerSupportFunction(FilterContext, SF_REQ_DISABLE_NOTIFICATIONS, 0, SF_NOTIFY_SEND_RAW_DATA, 0);
禁用未来原始数据的通知。 然后在 HTTP_FILTER_RAW_DATA 结构中,你得到了 pvInData,它是当前标头,我读入然后将其写入我分配的新 HTTP_FILTER_RAW_DATA (请记住对结构和 pvInData 使用 FilterContext->AllocMem )。 完成后,将新标头写入 FilterContext->WriteClient 并返回 SF_STATUS_REQ_READ_NEXT。
另外,在初始化时请确保设置 SF_NOTIFY_ORDER_HIGH 和 SF_NOTIFY_SEND_RAW_DATA。
通过查看我的旧代码,这就是我所做的,它是专门删除一个标头(加上它还添加了一个标头),因此它肯定会执行您需要执行的操作。 我要说的唯一警告是,我记得与 RAW_DATA 有关的一些变化从 IIS5(当我写这篇文章时)到 IIS6+,但我从来不需要更新这个特定的 ISAPI,所以我不知道是否有机会影响它的完成方式或不是。 希望这对您有所帮助,尽管您的问题可能至少有一个风滚草! :)
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! :)
我使用此代码重写标头(Firefor 不渲染 HTML b/c 不存在内容类型标头)
I used this code to rewrite headers (Firefor not rendring HTML b/c no content type header present)