【发布时间】:2016-02-10 00:59:11
【问题描述】:
我看到我的 jersey+jetty 服务器在将请求传递给我的处理程序之前响应 100 continue 标头。我不想发送 100-Continue 而是根据请求的 URI/Headers 发送 3xx 响应。
这是调用 request.getInputStream() 的类 org.glassfish.jersey.servlet.WebComponent
public Value<Integer> service(
final URI baseUri,
final URI requestUri,
final HttpServletRequest servletRequest,
final HttpServletResponse servletResponse) throws ServletException, IOException {
ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri,
servletRequest.getMethod(), getSecurityContext(servletRequest), new ServletPropertiesDelegate(servletRequest));
requestContext.setEntityStream(servletRequest.getInputStream());
addRequestHeaders(servletRequest, requestContext);
当请求中的输入流被请求时,Jetty 会发送 100 Continue 标头。来自 org.eclipse.jetty.server.Request
@Override
public ServletInputStream getInputStream() throws IOException
{
if (_inputState != __NONE && _inputState != _STREAM)
throw new IllegalStateException("READER");
_inputState = _STREAM;
if (_channel.isExpecting100Continue())
_channel.continue100(_input.available());
return _input;
}
它调用 HttpChannel 以发送 100 Continue 标头
/**
* If the associated response has the Expect header set to 100 Continue,
* then accessing the input stream indicates that the handler/servlet
* is ready for the request body and thus a 100 Continue response is sent.
*
* @throws IOException if the InputStream cannot be created
*/
public void continue100(int available) throws IOException
{
// If the client is expecting 100 CONTINUE, then send it now.
// TODO: consider using an AtomicBoolean ?
if (isExpecting100Continue())
{
_expect100Continue = false;
// is content missing?
if (available == 0)
{
if (_response.isCommitted())
throw new IOException("Committed before 100 Continues");
// TODO: break this dependency with HttpGenerator
boolean committed = sendResponse(HttpGenerator.CONTINUE_100_INFO, null, false);
if (!committed)
throw new IOException("Concurrent commit while trying to send 100-Continue");
}
}
}
如何防止 jersey+jetty 在请求到达 jersey 标记的 URI 路径方法之前发回 100 继续?
【问题讨论】:
标签: java jetty jersey-2.0 jetty-9