如何知道 HTTP 请求是否来自 WebDav 客户端?

How to know if the HTTP request comes from an WebDav client?

我正在创建一个 Web 文件管理器,最近有人建议我在上面实现 WebDav,我认为这是一个非常好的主意。

我考虑过将 webdav 保持在单独的 URL 中,例如 /webdav,但现在我正在考虑将我创建的 Web 界面和 webdav 服务器保持在同一位置 URL.

为了知道我是否应该提供 HTML 页面或文件,我需要知道它是从浏览器访问还是从 webdav 服务器访问。我怎么知道? User-Agent 够用吗?

如果是这样,我应该将哪些用户代理视为 WebDav 客户端?

谢谢!

不要这样做。使用 User-Agent 来确定您的服务器将要表现出什么行为通常是一个坏主意,对于 WebDAV 来说也是一个坏主意。一些客户端使用不止 1 个用户代理,一些客户端使用非常通用的 (curl),而其他客户端根本不提供一个。它会使您的系统变得脆弱、容易出错并且不符合标准,因为我不能只构建一个 WebDAV 客户端并期望它能正常工作,除非我模仿其中一个公认的用户代理。

话虽这么说……您仍然可以避开 User-Agent。 WebDAV 使用 PROPFIND HTTP 方法,您可以使用它来准确确定 WebDAV 客户端是否正在连接。

但是,它仍然使用 GETPUT 来获取和存储文件,您 必须 在严格的 WebDAV 层次结构中构建系统.如果您现有的 url 结构已经 1:1 匹配文件系统层次结构,这可能有效。

在某些方面,您只是在构建一个 WebDAV 服务器,然后它只有 html 个集合索引,这实际上有点常见。

最后,考虑使用库而不是自己滚动。

来源:我是 popular webdav framework.

的作者

您可能会使用诸如已验证与未验证之类的东西来确定,但正如@evert 所说,不要这样做。同时阅读 DAV 规范 (RFC 2518) (http://www.webdav.org/specs/rfc2518.html)

In the absence of distributed authoring capabilities, it is acceptable to have no mapping of source resource(s) to the URI namespace. In fact, preventing access to the source resource(s) has desirable security benefits. However, if remote editing of the source resource(s) is desired, the source resource(s) should be given a location in the URI namespace. This source location should not be one of the locations at which the generated output is retrievable, since in general it is impossible for the server to differentiate requests for source resources from requests for process output resources. There is often a many-to-many relationship between source resources and output resources.

这里的重要部分是

This source location should not be one of the locations at which the >generated output is retrievable, since in general it is impossible for the >server to differentiate requests for source resources from requests for >process output resources