使用 Java Servlet API 发送 100 继续

发布于 2024-07-20 07:13:28 字数 140 浏览 5 评论 0原文

是否可以发送“100 Continue”HTTP 状态代码,然后在使用 Java Servlet API (HttpServletResponse) 处理整个请求后发送一些其他状态代码?

我找不到任何明确的“否”答案,尽管 API 似乎不支持它。

Is it possible to send "100 Continue" HTTP status code, and then later some other status code after processing entire request using Java Servlet API (HttpServletResponse)?

I can't find any definitive "No" answer, although API doesn't seem to support it.

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

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

发布评论

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

评论(4

输什么也不输骨气 2024-07-27 07:13:29

您是否想问如何在收到完整请求之前发送状态代码,以中断由于缺少标头字段而正在进行的请求? 标准 servlet 似乎不可能做到这一点。

您使用什么服务器?

某些服务器的 servlet 扩展可能允许这样做,例如 Tomcat 的 Comet servlet 可能会发送EventType.BEGIN 一旦标头可供处理,这可能允许您中断没有正确身份验证的 PUT。

或者,您的服务器可能有一个插件来根据标头拒绝请求。

Did you mean to ask How do I send a status code before the complete request is received, to interrupt an in-progress request due to a missing header field? It seems that's not possible with standard servlets.

What server are you using?

Some server's servlet extensions may allow this, e.g. Tomcat's Comet servlet might send EventType.BEGIN once the headers are available to process, which may allow you to interrupt a PUT that doesn't have the correct authentication.

Alternatively your server might have a plugin to reject requests based on headers.

九厘米的零° 2024-07-27 07:13:29

您的意思是状态代码 100 吗?

API 确实支持发送 SC_CONTINUE。

Do you mean status code 100 ?

The API does support sending SC_CONTINUE.

伴梦长久 2024-07-27 07:13:28

我假设你的意思是“100继续”。

答案是:不,你不能(至少不是它的预期方式,如 临时响应)。 一般来说,当请求需要时,Servlet 引擎会自动执行此操作。 当然,这使得 Servlet 不可能阻止发送 100 状态 —— 这个问题是 Servlet API 中的一个已知问题,而且已经知道了很久了。

I assume you mean "100 Continue".

The answer is: no, you can't (at least not the way it's intended, as provisional response). In general, the servlet engine will do it automatically, when the request requires it. Of course this makes it impossibe for the servlet to prevent sending the 100 status -- this issue is a known problem in the Servlet API, and has been known for what feels like eons now.

ゝ杯具 2024-07-27 07:13:28

我知道 Jetty 会等到 getReader() 或 getInputStream()在发送 100 之前调用。我认为这就是您正在寻找的行为。 我不知道Tomcat是做什么的。

I know that Jetty will wait until getReader() or getInputStream() is called before it sends a 100. I think this is the behavior you are looking for. I don't know what Tomcat does.

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