@Test public void testNotModifiedDoesNotSetAutomaticallySetContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 304, MultiMap.caseInsensitiveMultiMap()); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testHeadDoesNotSetAutomaticallySetContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.HEAD, 200, MultiMap.caseInsensitiveMultiMap()); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void test1xxRemovesTransferEncodingHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 102, MultiMap.caseInsensitiveMultiMap().set("transfer-encoding", "chunked")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testHeadRemovesTransferEncodingHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.HEAD, 200, MultiMap.caseInsensitiveMultiMap().set("transfer-encoding", "chunked")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testNoContentRemovesContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 204, MultiMap.caseInsensitiveMultiMap().set("content-length", "34")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testNoContentRemovesTransferEncodingHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 204, MultiMap.caseInsensitiveMultiMap().set("transfer-encoding", "chunked")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testNotModifiedRemovesTransferEncodingHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 304, MultiMap.caseInsensitiveMultiMap().set("transfer-encoding", "chunked")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void test1xxRemovesContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 102, MultiMap.caseInsensitiveMultiMap().set("content-length", "34")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testServerConnectionHandler() throws Exception { AtomicInteger status = new AtomicInteger(); AtomicReference<HttpConnection> connRef = new AtomicReference<>(); server.connectionHandler(conn -> { assertEquals(0, status.getAndIncrement()); assertNull(connRef.getAndSet(conn)); }); server.requestHandler(req -> { assertEquals(1, status.getAndIncrement()); assertSame(connRef.get(), req.connection()); req.response().end(); }); CountDownLatch listenLatch = new CountDownLatch(1); server.listen(onSuccess(s -> listenLatch.countDown())); awaitLatch(listenLatch); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> { testComplete(); }); await(); }
@Test public void testRequestTimeoutCanceledWhenRequestEndsNormally() { server.requestHandler(req -> req.response().end()); server.listen(onSuccess(s -> { AtomicReference<Throwable> exception = new AtomicReference<>(); // There is no server running, should fail to connect HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.exceptionHandler(exception::set); req.setTimeout(500); req.end(); vertx.setTimer(1000, id -> { assertNull("Did not expect any exception", exception.get()); testComplete(); }); })); await(); }
@Test public void testNoParams() { server.requestHandler(req -> { assertNull(req.query()); assertTrue(req.params().isEmpty()); req.response().end(); }); server.listen(onSuccess(server -> { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete()).end(); })); await(); }
@Test public void testMultipleServerClose() { this.server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)); AtomicInteger times = new AtomicInteger(); // We assume the endHandler and the close completion handler are invoked in the same context task ThreadLocal stack = new ThreadLocal(); stack.set(true); server.requestStream().endHandler(v -> { assertNull(stack.get()); assertTrue(Vertx.currentContext().isEventLoopContext()); times.incrementAndGet(); }); server.close(ar1 -> { assertNull(stack.get()); assertTrue(Vertx.currentContext().isEventLoopContext()); server.close(ar2 -> { server.close(ar3 -> { assertEquals(1, times.get()); testComplete(); }); }); }); await(); }
@Test public void testResetContentSetsContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 205, MultiMap.caseInsensitiveMultiMap()); assertEquals("0", respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testHeadHasNoContentLengthByDefault() { server.requestHandler(req -> { assertEquals(HttpMethod.HEAD, req.method()); // By default HEAD does not have a content-length header req.response().end(); }); server.listen(onSuccess(s -> { client.request(HttpMethod.HEAD, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { assertNull(resp.headers().get(HttpHeaders.CONTENT_LENGTH)); resp.endHandler(v -> testComplete()); })).end(); })); await(); }
@Test public void testHeadAllowsContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.HEAD, 200, MultiMap.caseInsensitiveMultiMap().set("content-length", "34")); assertEquals("34", respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testNotModifiedAllowsContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 304, MultiMap.caseInsensitiveMultiMap().set("content-length", "34")); assertEquals("34", respHeaders.get("Content-Length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testResetContentRemovesTransferEncodingHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 205, MultiMap.caseInsensitiveMultiMap().set("transfer-encoding", "chunked")); assertEquals("0", respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void testHeadDoesNotSetAutomaticallySetContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.HEAD, 200, MultiMap.caseInsensitiveMultiMap()); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void test1xxRemovesContentLengthHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 102, MultiMap.caseInsensitiveMultiMap().set("content-length", "34")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }
@Test public void test1xxRemovesTransferEncodingHeader() throws Exception { MultiMap respHeaders = checkEmptyHttpResponse(HttpMethod.GET, 102, MultiMap.caseInsensitiveMultiMap().set("transfer-encoding", "chunked")); assertNull(respHeaders.get("content-length")); assertNull(respHeaders.get("transfer-encoding")); }