使用前端控制器和 IIS 提供静态文件的方法?

发布于 2024-10-07 06:40:33 字数 665 浏览 5 评论 0原文

背景

IIS ISAPI 过滤器将所有请求路由到前端控制器 Java CMS 进行响应。没有物理文件对应于给定的 URL。动机:

  1. 保护 URL
  2. 实施 SSL

这是服务静态文件(例如音频和视频)的性能瓶颈。并且,池化的应用程序服务器处理线程被占用来服务响应。

想法

让应用程序服务器填充一个 IIS ISAPI 过滤器或 httpmodule,它可以读取文件,然后提供文件服务。可能使用物理文件路径、内容长度和 MIME 类型填充响应标头。

问题

  1. 没有让 IIS 直接提供文件服务是错误的设计决策吗?如果是这样,请提供有关在安全性和 SSL 实施方面应注意哪些方面的建议(CMS 处理这两个方面)。
  2. 如果让 IIS 响应,如何利用 IIS 静态文件缓存?或者说缓存有多大好处?

Background

An IIS ISAPI filter routes all requests to a front controller Java CMS for response. No physical file corresponds to a given URL. Motivations:

  1. Securing URLs
  2. Enforcing SSL

This is a performance bottleneck serving static files such as audio and video. And, pooled application server processing threads are occupied serving the response.

Idea

Have the application server populate an IIS ISAPI Filter, or httpmodule, that can read and then serve the file instead. Possibly populate response header(s) with physical file path, content length, and mime-type.

Questions

  1. Bad design decision not having IIS serve the files directly? If so, suggestions for what to look at in terms of security and SSL enforcement (CMS handles both) .
  2. If going with having IIS respond, what to do to take advantage of IIS static file caching? Or how much benefit is the cache?

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

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

发布评论

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

评论(2

远昼 2024-10-14 06:40:34

我认为您应该允许 IIS 提供静态文件。您可以让 HttpModule(或您的过滤器)将控制权转移回 IIS - 这意味着可能必须复制安全强制代码。另一种方法是让应用程序服务器将控制权转移回 IIS 来提供文件服务(安全检查当然会在之前进行)。或者最后,正如您所概述的,您的应用程序服务器可以注入响应标头,然后 httpmodule 会读取它们并将控制权传递给 IIS。不确定java,但在.NET中你可以使用 HttpResponse.TransmitFile 方法将控制权传回 IIS - 这应该避免需要使 HttpModule 提供文件。

最后,对于缓存,您始终可以发出缓存标头以响应较低级别(代理或客户端缓存)。如果文件正在更改,那么您可以添加文件依赖项等。

编辑:不确定这是否适合您。创建一个 http 处理程序 (ashx) 并将其标记为 IIS 中所需的 SSL。所有媒体文件都将由该处理程序提供服务。该处理程序将把文件作为查询参数。现在,您可以传递一些文件标识符或加密的部分路径(相对于文件存储的配置基本路径),以便用户看不到实际的文件名或路径。您甚至可以制作将在一段时间后过期的令牌(本质上是附加文件 ID 和时间戳并对其进行加密),以便用户无法使用相同的参数再次请求相同的文件。处理程序的伪代码是

void ProcessRequest(HttpContext context)
{
    // read file id/name token
    var token = context.Request["q"];

    // validate/decrypt token etc and get the actual path for file to be served
    string filePath;

    // set needed response headers - content-type, content-disposition and cache related
    ...

    // ask IIS to serve the file
    context.Response.TransmitFile(filePath);
}

I believe that you should allow IIS to serve the static files. You can have HttpModule (or your filter) transferring the control back to IIS - it means that security enforcement code may have to be replicated. Yet another approach can be to make application server transfer control back to IIS to serve the file (security checking would of course happen before). Or lastly, as outlined by you, your app server can inject response headers and then httpmodule would read them and pass control to IIS. Not sure about java but in .NET you can use HttpResponse.TransmitFile method to pass back control to IIS - this should avoid need to make HttpModule serve file.

Finally, for caching, you can always emit cache headers in response to have down level (proxy or client side caching). If files are changing then you can add file dependency etc.

EDIT: Not sure if this will work for you. Create an http handler (ashx) and marked it as SSL required in IIS. All media files will be served by this handler. The handler would take file to be served as query parameter. Now, you may pass some file identifier or encrypted partial path (relative to configured base path to file store) so that actual file name or paths are not visible to user. You can even make tokens that would expire in some time (essentially, append file id & time-stamp and encrypt it) so that user cannot request same file again using same parameter. Pseudo-code for handler would be

void ProcessRequest(HttpContext context)
{
    // read file id/name token
    var token = context.Request["q"];

    // validate/decrypt token etc and get the actual path for file to be served
    string filePath;

    // set needed response headers - content-type, content-disposition and cache related
    ...

    // ask IIS to serve the file
    context.Response.TransmitFile(filePath);
}
時窥 2024-10-14 06:40:34

这可能有效:

http://www.helicontech.com/ape/

特别是 x-sendfile 部分。

This may work:

http://www.helicontech.com/ape/

Specifically the x-sendfile piece.

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