use of io.netty.handler.codec.http2.DefaultHttp2Headers in project vert.x by eclipse.
the class Http2ServerTest method testURI.
@Test
public void testURI() throws Exception {
server.requestHandler(req -> {
assertEquals("/some/path", req.path());
assertEquals("foo=foo_value&bar=bar_value_1&bar=bar_value_2", req.query());
assertEquals("/some/path?foo=foo_value&bar=bar_value_1&bar=bar_value_2", req.uri());
assertEquals("http://whatever.com/some/path?foo=foo_value&bar=bar_value_1&bar=bar_value_2", req.absoluteURI());
assertEquals("whatever.com", req.host());
MultiMap params = req.params();
Set<String> names = params.names();
assertEquals(2, names.size());
assertTrue(names.contains("foo"));
assertTrue(names.contains("bar"));
assertEquals("foo_value", params.get("foo"));
assertEquals(Collections.singletonList("foo_value"), params.getAll("foo"));
assertEquals("bar_value_1", params.get("bar"));
assertEquals(Arrays.asList("bar_value_1", "bar_value_2"), params.getAll("bar"));
testComplete();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2Headers headers = new DefaultHttp2Headers().method("GET").scheme("http").authority("whatever.com").path("/some/path?foo=foo_value&bar=bar_value_1&bar=bar_value_2");
request.encoder.writeHeaders(request.context, id, headers, 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project vert.x by eclipse.
the class Http2ServerTest method testConnect.
@Test
public void testConnect() throws Exception {
server.requestHandler(req -> {
assertEquals(HttpMethod.CONNECT, req.method());
assertEquals("whatever.com", req.host());
assertNull(req.path());
assertNull(req.query());
assertNull(req.scheme());
assertNull(req.uri());
assertNull(req.absoluteURI());
testComplete();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2Headers headers = new DefaultHttp2Headers().method("CONNECT").authority("whatever.com");
request.encoder.writeHeaders(request.context, id, headers, 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project vert.x by eclipse.
the class Http2HeadersAdaptorsTest method setUp.
@Before
public void setUp() {
headers = new DefaultHttp2Headers();
map = new Http2HeadersAdaptor(headers);
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project vert.x by eclipse.
the class Http2ServerConnection method doSendPush.
private synchronized void doSendPush(int streamId, String host, HttpMethod method, MultiMap headers, String path, StreamPriority streamPriority, Promise<HttpServerResponse> promise) {
Http2Headers headers_ = new DefaultHttp2Headers();
headers_.method(method.name());
headers_.path(path);
headers_.scheme(isSsl() ? "https" : "http");
if (host != null) {
headers_.authority(host);
}
if (headers != null) {
headers.forEach(header -> headers_.add(header.getKey(), header.getValue()));
}
handler.writePushPromise(streamId, headers_, new Handler<AsyncResult<Integer>>() {
@Override
public void handle(AsyncResult<Integer> ar) {
if (ar.succeeded()) {
synchronized (Http2ServerConnection.this) {
int promisedStreamId = ar.result();
String contentEncoding = HttpUtils.determineContentEncoding(headers_);
Http2Stream promisedStream = handler.connection().stream(promisedStreamId);
Push push = new Push(context, contentEncoding, method, path, promise);
push.priority(streamPriority);
push.init(promisedStream);
int maxConcurrentStreams = handler.maxConcurrentStreams();
if (concurrentStreams < maxConcurrentStreams) {
concurrentStreams++;
push.complete();
} else {
pendingPushes.add(push);
}
}
} else {
promise.fail(ar.cause());
}
}
});
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project vert.x by eclipse.
the class Http2ClientTest method testClientStreamPriorityNoChange.
@Ignore("Cannot pass reliably for now (https://github.com/netty/netty/issues/9842)")
@Test
public void testClientStreamPriorityNoChange() throws Exception {
StreamPriority streamPriority = new StreamPriority().setDependency(123).setWeight((short) 45).setExclusive(true);
waitFor(2);
Promise<Void> latch = Promise.promise();
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(streamPriority.getDependency(), streamDependency);
assertEquals(streamPriority.getWeight(), weight);
assertEquals(streamPriority.isExclusive(), exclusive);
assertFalse(endStream);
latch.complete();
});
encoder.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, true, ctx.newPromise());
ctx.flush();
}
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive) throws Http2Exception {
fail("Priority frame should not be sent");
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
if (endOfStream) {
vertx.runOnContext(v -> {
complete();
});
}
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.request(new RequestOptions().setHost(DEFAULT_HTTPS_HOST).setPort(DEFAULT_HTTPS_PORT).setURI("/somepath")).onComplete(onSuccess(req -> {
req.response(onSuccess(resp -> {
resp.endHandler(v -> {
complete();
});
})).setStreamPriority(streamPriority);
req.sendHead();
latch.future().onComplete(onSuccess(v -> {
req.setStreamPriority(streamPriority);
req.end();
}));
}));
await();
} finally {
s.channel().close().sync();
}
}
Aggregations