【问题标题】:Is there a way to prevent Jetty from sending a content length header on head requests?有没有办法阻止 Jetty 在头部请求中发送内容长度标头?
【发布时间】:2023-03-03 09:00:24
【问题描述】:

当 HEAD 请求返回 0 作为内容长度时,我正在尝试向不喜欢它的设备提供数据。实际的 GET 响应是分块的,所以我没有内容长度。

Jetty 自行添加内容长度 0。我尝试使用FilterHttpServletResponseWrapper 来删除标题,但没有一个标题方法被调用用于“Content-Length”。

那么有什么方法可以删除该标题吗?

谢谢。

【问题讨论】:

  • 你用的是什么版本的码头?
  • 我想我应该提到这一点。 8.1.12.v20130726,由于依赖关系,我有点卡在那个上面。
  • 我检查了 9 号码头,并在那里实施了正确的行为。不幸的是,jetty 8 已停产,我们没有发布任何新版本(除非商业客户需要......)。如果您想自己尝试修复,那么我们很乐意接受 github 上的拉取请求并回答邮件列表/IRC 上的问题以帮助您。

标签: servlets jetty servlet-filters embedded-jetty


【解决方案1】:

听起来很可疑。

提交了一个关于它的错误https://github.com/eclipse/jetty.project/issues/596

根据规范 - https://www.rfc-editor.org/rfc/rfc7231#section-4.3.2

The HEAD method is identical to GET except that the server MUST NOT
send a message body in the response (i.e., the response terminates at
the end of the header section).  The server SHOULD send the same
header fields in response to a HEAD request as it would have sent if
the request had been a GET, except that the payload header fields
(Section 3.3) MAY be omitted.  This method can be used for obtaining
metadata about the selected representation without transferring the
representation data and is often used for testing hypertext links for
validity, accessibility, and recent modification.

因此,如果您在 Transfer-Encoding: chunked 的资源上请求 HEAD,则确实不会提供 Content-Length

【讨论】:

  • 感谢提交错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-04
  • 2013-08-13
  • 2020-09-20
  • 1970-01-01
相关资源
最近更新 更多