确定 ISAPI 过滤器的响应长度

发布于 2024-07-14 10:17:35 字数 503 浏览 4 评论 0原文

我正在开发一个 ISAPI 过滤器,以从响应中删除某些内容。 我需要在进行处理之前收集响应的所有正文,因为我要剥离的内容可能会与发送缓冲区重叠。

为此,我想缓冲每个 SF_NOTIFY_SEND_RAW_DATA 通知的响应内容,直到到达最后一个通知,然后发送翻译后的数据。 我想知道确定哪个 SF_NOTIFY_SEND_RAW_DATA 实际上是最后一个的最佳方法。 如果我等到SF_NOTIFY_END_OF_REQUEST通知,那么我不知道如何发送我缓冲的数据。

一种方法是使用内容长度。 这需要我检测标头的末尾。 它还需要假设内容长度标头是正确的(可以保证吗?)。 由于 HTTP 甚至不需要内容长度标头,我什至不确定它是否会一直存在。 似乎应该有一个更简单的方法。

我假设响应没有分块,因此在更改响应之前我不会处理分块。 另外,当我对响应正文进行修改时,响应正文的大小不会改变,因此我不需要返回并更新内容长度。

I am working on an ISAPI Filter to strip certain content out of responses. I need to collect all the body of the response before I do the processing, as the content I'm stripping could overlap send buffers.

To do this I'd like to buffer the response content with each SF_NOTIFY_SEND_RAW_DATA notification until I get to the last one, then send the translated data. I would like to know the best way to determine which SF_NOTIFY_SEND_RAW_DATA is actually the last. If I wait until the SF_NOTIFY_END_OF_REQUESTnotification, then I don't know how to send the data I've buffered.

One approach would be to use the content-length. This would require I detect the end of the headers. It would also require assuming the content-length header is correct (is that guaranteed?). Since HTTP doesn't even require a content-length header, I'm not even sure it will always be there. There seems like there should be an easier way.

I'm assuming the response is not chunked, so I am not handling dechunking before I do the response change. Also, when I do the modifications to the response body, the size of teh response body will not change, so I do not need to go back and update the content-length.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青丝拂面 2024-07-21 10:17:35

我最终通过谷歌找到了一些很好的讨论。

这篇文章回答了我的问题,并提出了更复杂的过滤器必须解决的问题:http://groups.google.com/group/microsoft.public.platformsdk.internet.server.isapi-dev/browse_thread/thread/85a5e75f342fad2b/cbb638f9a85c9e03?q=HTTP_FILTER_RAW_DATA&_done=%2Fgroups%3Fq%3DHTTP_FILTER_RAW_DATA%26start% 3D20%26&_doneTitle=Back+to+Search&&d&pli=1

我的过滤器将完整请求缓冲到自己的缓冲区中,然后使用 SF_NOTIFY_END_OF_REQUEST 发送内容。 它所做的修改不会改变大小,并且排除了响应被分块的可能性,所以在我的例子中,过滤器相对简单。

I eventually found some good discussions via google.

This posts answers my questions, as well as raises issues a more complicated filter would have to address: http://groups.google.com/group/microsoft.public.platformsdk.internet.server.isapi-dev/browse_thread/thread/85a5e75f342fad2b/cbb638f9a85c9e03?q=HTTP_FILTER_RAW_DATA&_done=%2Fgroups%3Fq%3DHTTP_FILTER_RAW_DATA%26start%3D20%26&_doneTitle=Back+to+Search&&d&pli=1

The filter I have s buffering the full request into its own buffer then using the SF_NOTIFY_END_OF_REQUEST to send the contents. The modification it does does not change the size, and precludes the possibility that the response is chunked, so in my case the filter is relatively simple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文