394552 - HEAD requests don't work for jetty-client.
Added a missing call to HttpParser.setHeadResponse() to inform the parser that it is a response to a HEAD request.
This commit is contained in:
parent
4d34e83c1c
commit
58dff061e1
|
@ -36,6 +36,7 @@ import org.eclipse.jetty.client.api.Response;
|
||||||
import org.eclipse.jetty.client.api.Result;
|
import org.eclipse.jetty.client.api.Result;
|
||||||
import org.eclipse.jetty.http.HttpField;
|
import org.eclipse.jetty.http.HttpField;
|
||||||
import org.eclipse.jetty.http.HttpHeader;
|
import org.eclipse.jetty.http.HttpHeader;
|
||||||
|
import org.eclipse.jetty.http.HttpMethod;
|
||||||
import org.eclipse.jetty.http.HttpParser;
|
import org.eclipse.jetty.http.HttpParser;
|
||||||
import org.eclipse.jetty.http.HttpVersion;
|
import org.eclipse.jetty.http.HttpVersion;
|
||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
|
@ -141,6 +142,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
||||||
HttpConversation conversation = exchange.getConversation();
|
HttpConversation conversation = exchange.getConversation();
|
||||||
HttpResponse response = exchange.getResponse();
|
HttpResponse response = exchange.getResponse();
|
||||||
|
|
||||||
|
parser.setHeadResponse(exchange.getRequest().getMethod() == HttpMethod.HEAD);
|
||||||
response.version(version).status(status).reason(reason);
|
response.version(version).status(status).reason(reason);
|
||||||
|
|
||||||
// Probe the protocol handlers
|
// Probe the protocol handlers
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.eclipse.jetty.client.api.Response;
|
||||||
import org.eclipse.jetty.client.api.Result;
|
import org.eclipse.jetty.client.api.Result;
|
||||||
import org.eclipse.jetty.client.util.BytesContentProvider;
|
import org.eclipse.jetty.client.util.BytesContentProvider;
|
||||||
import org.eclipse.jetty.http.HttpField;
|
import org.eclipse.jetty.http.HttpField;
|
||||||
|
import org.eclipse.jetty.http.HttpMethod;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||||
|
@ -671,4 +672,41 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
Assert.assertEquals(200, response.getStatus());
|
Assert.assertEquals(200, response.getStatus());
|
||||||
Assert.assertFalse(response.getHeaders().containsKey(headerName));
|
Assert.assertFalse(response.getHeaders().containsKey(headerName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_HEAD_With_ResponseContentLength() throws Exception
|
||||||
|
{
|
||||||
|
final int length = 1024;
|
||||||
|
start(new AbstractHandler()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
|
{
|
||||||
|
baseRequest.setHandled(true);
|
||||||
|
response.getOutputStream().write(new byte[length]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// HEAD requests receive a Content-Length header, but do not
|
||||||
|
// receive the content so they must handle this case properly
|
||||||
|
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
|
||||||
|
.scheme(scheme)
|
||||||
|
.method(HttpMethod.HEAD)
|
||||||
|
.send()
|
||||||
|
.get(5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(200, response.getStatus());
|
||||||
|
Assert.assertEquals(0, response.getContent().length);
|
||||||
|
|
||||||
|
// Perform a normal GET request to be sure the content is now read
|
||||||
|
response = client.newRequest("localhost", connector.getLocalPort())
|
||||||
|
.scheme(scheme)
|
||||||
|
.send()
|
||||||
|
.get(5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(200, response.getStatus());
|
||||||
|
Assert.assertEquals(length, response.getContent().length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue