HTTP HEAD 响应 - 设置内容长度
我正在尝试为我们的一项服务构建一个 HEAD 方法,以便客户可以在决定是否下载之前查看内容类型和大小。
如何设置响应头的内容长度?使用 HttpContext 公开 ContentType、编码等,但我无法指定长度,因为我假设该值通常是在将某些内容添加到响应时由框架添加的。
是否有另一种方法可以做到这一点,或者我是否错误地设置了 HEAD 请求的长度 - 我实际上应该添加自定义标头来返回资源的大小吗?
I'm trying to build a HEAD method to one of our services so that clients can peek at the content type and size before deciding whether to download it.
How can I set the Content Length of the response header? Using HttpContext exposes the ContentType, Encoding etc but I can't specify a length as I presume this value is normally added by the framework when some content is added to the response.
Is there another way of doing this or am I incorrect to be setting the length for a HEAD request - should I actually be adding a custom header to return the size of the resource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
Content-Length
指定响应正文的大小 - 而不是资源的大小。因此,它在HEAD
响应的上下文中没有意义。编辑:规格说明:
-- http://www.w3.org/Protocols/ rfc2616/rfc2616-sec9.html#sec9.4
这表明我上面的说法是错误的。特别是后一段强烈建议 HEAD 可以有一个
Content-Length
标头。I think a
Content-Length
specifies the size of the body of the response - not the size of the resource. As such, it doesn't make sense in the context of aHEAD
response.Edit: The specs says:
-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4
This suggests that my above statement is wrong. Especially the latter paragraph strongly suggests that a HEAD can have a
Content-Length
header.