Fixes #1878 - Handle 100 Continue response without Expect header.

This commit is contained in:
Simone Bordet 2017-10-09 12:08:24 +02:00
parent bc7d53b43f
commit c69c7b29c7
3 changed files with 32 additions and 6 deletions

View File

@ -24,8 +24,6 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.util.BufferingResponseListener;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
/**
* <p>A protocol handler that handles the 100 response code.</p>
@ -51,10 +49,8 @@ public class ContinueProtocolHandler implements ProtocolHandler
@Override
public boolean accept(Request request, Response response)
{
boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
HttpConversation conversation = ((HttpRequest)request).getConversation();
boolean handled100 = conversation.getAttribute(ATTRIBUTE) != null;
return expect100 && !handled100;
return conversation.getAttribute(ATTRIBUTE) == null;
}
@Override

View File

@ -743,7 +743,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
return committing;
}
protected boolean sendResponse(MetaData.Response info, ByteBuffer content, boolean complete) throws IOException
public boolean sendResponse(MetaData.Response info, ByteBuffer content, boolean complete) throws IOException
{
try(Blocker blocker = _response.getHttpOutput().acquireWriteBlockingCallback())
{

View File

@ -27,6 +27,7 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -42,9 +43,11 @@ import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.util.BufferingResponseListener;
import org.eclipse.jetty.client.util.BytesContentProvider;
import org.eclipse.jetty.client.util.DeferredContentProvider;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
@ -698,4 +701,31 @@ public class HttpClientContinueTest extends AbstractTest
}
}
}
@Test
public void test_NoExpect_Respond100Continue() throws Exception
{
start(new AbstractHandler.ErrorDispatchHandler()
{
@Override
protected void doNonErrorHandle(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
jettyRequest.setHandled(true);
// Force a 100 Continue response.
jettyRequest.getHttpChannel().sendResponse(HttpGenerator.CONTINUE_100_INFO, null, false);
// Echo the content.
IO.copy(request.getInputStream(), response.getOutputStream());
}
});
byte[] bytes = new byte[1024];
new Random().nextBytes(bytes);
ContentResponse response = client.newRequest(newURI())
.content(new BytesContentProvider(bytes))
.timeout(5, TimeUnit.SECONDS)
.send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
Assert.assertArrayEquals(bytes, response.getContent());
}
}