use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testUseResponseAfterComplete.
@Test
public void testUseResponseAfterComplete() {
server.requestHandler(req -> {
Buffer buff = Buffer.buffer();
HttpServerResponse resp = req.response();
assertFalse(resp.ended());
resp.end();
assertTrue(resp.ended());
assertIllegalStateException(() -> resp.drainHandler(noOpHandler()));
assertIllegalStateException(() -> resp.end());
assertIllegalStateException(() -> resp.end("foo"));
assertIllegalStateException(() -> resp.end(buff));
assertIllegalStateException(() -> resp.end("foo", "UTF-8"));
assertIllegalStateException(() -> resp.exceptionHandler(noOpHandler()));
assertIllegalStateException(() -> resp.setChunked(false));
assertIllegalStateException(() -> resp.setWriteQueueMaxSize(123));
assertIllegalStateException(() -> resp.write(buff));
assertIllegalStateException(() -> resp.write("foo"));
assertIllegalStateException(() -> resp.write("foo", "UTF-8"));
assertIllegalStateException(() -> resp.write(buff));
assertIllegalStateException(() -> resp.writeQueueFull());
assertIllegalStateException(() -> resp.sendFile("asokdasokd"));
testComplete();
});
server.listen(onSuccess(s -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()).end();
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testRequestBodyStringAtEnd.
private void testRequestBodyStringAtEnd(String encoding) {
String body = TestUtils.randomUnicodeString(1000);
Buffer bodyBuff;
if (encoding == null) {
bodyBuff = Buffer.buffer(body);
} else {
bodyBuff = Buffer.buffer(body, encoding);
}
server.requestHandler(req -> {
req.bodyHandler(buffer -> {
assertEquals(bodyBuff, buffer);
testComplete();
});
});
server.listen(onSuccess(server -> {
HttpClientRequest req = client.request(HttpMethod.POST, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler());
if (encoding == null) {
req.end(body);
} else {
req.end(body, encoding);
}
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testResponseBodyWriteString.
private void testResponseBodyWriteString(boolean chunked, String encoding) {
String body = TestUtils.randomUnicodeString(1000);
Buffer bodyBuff;
if (encoding == null) {
bodyBuff = Buffer.buffer(body);
} else {
bodyBuff = Buffer.buffer(body, encoding);
}
server.requestHandler(req -> {
if (chunked) {
req.response().setChunked(true);
} else {
req.response().headers().set("Content-Length", String.valueOf(bodyBuff.length()));
}
if (encoding == null) {
req.response().write(body);
} else {
req.response().write(body, encoding);
}
req.response().end();
});
server.listen(onSuccess(s -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.bodyHandler(buff -> {
assertEquals(bodyBuff, buff);
testComplete();
});
}).end();
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testResponseBodyBufferAtEnd.
@Test
public void testResponseBodyBufferAtEnd() {
Buffer body = TestUtils.randomBuffer(1000);
server.requestHandler(req -> {
req.response().end(body);
});
server.listen(onSuccess(s -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.bodyHandler(buff -> {
assertEquals(body, buff);
testComplete();
});
}).end();
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method test100ContinueHandledAutomatically.
@Test
public void test100ContinueHandledAutomatically() throws Exception {
Buffer toSend = TestUtils.randomBuffer(1000);
server.requestHandler(req -> {
req.bodyHandler(data -> {
assertEquals(toSend, data);
req.response().end();
});
});
server.listen(onSuccess(s -> {
HttpClientRequest req = client.request(HttpMethod.PUT, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.endHandler(v -> testComplete());
});
req.headers().set("Expect", "100-continue");
req.setChunked(true);
req.continueHandler(v -> {
req.write(toSend);
req.end();
});
req.sendHead();
}));
await();
}
Aggregations