From 3e42b68d9e219b9ce5a18a4b4f6fdb7ac0fb6e52 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 16 Dec 2016 15:34:13 +0100 Subject: [PATCH] Added test cases for HEAD requests. --- .../jetty/http/client/HttpClientTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java index a9b817663c0..49898a4d0c1 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java @@ -33,6 +33,7 @@ import java.util.stream.IntStream; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -505,6 +506,40 @@ public class HttpClientTest extends AbstractTest Assert.assertEquals(1, completes.get()); } + @Test + public void testHEADResponds200() throws Exception + { + testHEAD(servletPath, HttpStatus.OK_200); + } + + @Test + public void testHEADResponds404() throws Exception + { + testHEAD("/notMapped", HttpStatus.NOT_FOUND_404); + } + + private void testHEAD(String path, int status) throws Exception + { + byte[] data = new byte[1024]; + new Random().nextBytes(data); + start(new HttpServlet() + { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + response.getOutputStream().write(data); + } + }); + + ContentResponse response = client.newRequest(newURI()) + .method(HttpMethod.HEAD) + .path(path) + .send(); + + Assert.assertEquals(status, response.getStatus()); + Assert.assertEquals(0, response.getContent().length); + } + private void sleep(long time) throws IOException { try