简体   繁体   English

发送100继续使用Java Servlet API

[英]Sending 100 Continue using Java Servlet 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)? 是否可以使用Java Servlet API(HttpServletResponse)处理整个请求后发送“100 Continue”HTTP状态代码,然后再发送一些其他状态代码?

I can't find any definitive "No" answer, although API doesn't seem to support it. 虽然API似乎不支持它,但我找不到任何明确的“否”答案。

I assume you mean "100 Continue". 我假设你的意思是“100继续”。

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. 通常,servlet引擎会在请求需要时自动执行。 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. 当然,这使得servlet无法阻止发送100状态 - 这个问题是Servlet API中的一个已知问题,并且已经知道现在感觉像是eons。

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. 我知道Jetty会等到getReader()或getInputStream()在它发送100之前被调用 。我认为这是你正在寻找的行为。 I don't know what Tomcat does. 我不知道Tomcat做了什么。

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. 似乎用标准servlet是不可能的。

What server are you using? 你用的是什么服务器?

Some server's servlet extensions may allow this, eg 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. 某些服务器的servlet扩展可能允许这样做,例如,一旦标头可用于处理, Tomcat的Comet servlet可能会发送EventType.BEGIN,这可能允许您中断没有正确身份验证的PUT。

Alternatively your server might have a plugin to reject requests based on headers. 或者,您的服务器可能有一个插件来拒绝基于标头的请求。

Do you mean status code 100 ? 你的意思是状态码100吗?

The API does support sending SC_CONTINUE. API支持发送SC_CONTINUE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM