Skip to content

Commit

Permalink
Update HttpConnection to be server agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 13, 2016
1 parent c001770 commit 8ebf204
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
30 changes: 15 additions & 15 deletions src/main/java/io/vertx/core/http/HttpConnection.java
Expand Up @@ -83,17 +83,17 @@ default HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData
}

/**
* Send a go away frame to the client.<p/>
* Send a go away frame to the remote endpoint of the connection.<p/>
*
* <ul>
* <li>a {@literal GOAWAY} frame is sent to the to the client with the {@code errorCode} and {@@code debugData}</li>
* <li>a {@literal GOAWAY} frame is sent to the to the remote endpoint with the {@code errorCode} and {@@code debugData}</li>
* <li>any stream created after the stream identified by {@code lastStreamId} will be closed</li>
* <li>for an {@literal errorCode} is different than {@literal 0} when all the remaining streams are closed this connection will be closed automatically</li>
* </ul>
*
* @param errorCode the {@literal GOAWAY} error code
* @param lastStreamId the last stream id
* @param debugData additional debug data sent to the client
* @param debugData additional debug data sent to the remote endpoint
* @param completionHandler the handler notified when all stream have been closed
* @return a reference to this, so the API can be used fluently
*/
Expand Down Expand Up @@ -128,12 +128,12 @@ default HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData
HttpConnection closeHandler(Handler<Void> handler);

/**
* @return the latest server settings acknowledged by the client
* @return the latest server settings acknowledged by the remote endpoint
*/
Http2Settings settings();

/**
* Send to the client an update of the server settings.
* Send to the remote endpoint an update of the server settings.
*
* @param settings the new settings
* @return a reference to this, so the API can be used fluently
Expand All @@ -142,36 +142,36 @@ default HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData
HttpConnection updateSettings(Http2Settings settings);

/**
* Send to the client an update of the server settings.<p/>
* Send to the remote endpoint an update of this endpoint settings.<p/>
*
* The {@code completionHandler} will be notified when the client has acknowledged the settings.
* The {@code completionHandler} will be notified when the remote endpoint has acknowledged the settings.
*
* @param settings the new settings
* @param completionHandler the handler notified when the settings have been acknowledged by the client
* @param completionHandler the handler notified when the settings have been acknowledged by the remote endpoint
* @return a reference to this, so the API can be used fluently
*/
@Fluent
HttpConnection updateSettings(Http2Settings settings, Handler<AsyncResult<Void>> completionHandler);

/**
* @return the current client settings for this connection
* @return the current remote endpoint settings for this connection
*/
Http2Settings clientSettings();
Http2Settings remoteSettings();

/**
* Set an handler that is called when client {@link Http2Settings} are updated.
* Set an handler that is called when remote endpoint {@link Http2Settings} are updated.
*
* @param handler the handler for client settings
* @param handler the handler for remote endpoint settings
* @return a reference to this, so the API can be used fluently
*/
@Fluent
HttpConnection clientSettingsHandler(Handler<Http2Settings> handler);
HttpConnection remoteSettingsHandler(Handler<Http2Settings> handler);

/**
* @return the handler for client settings
* @return the handler for remote endpoint settings
*/
@GenIgnore
Handler<Http2Settings> clientSettingsHandler();
Handler<Http2Settings> remoteSettingsHandler();

/**
* Set an handler called when a connection error happens
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/vertx/core/http/impl/VertxHttp2Handler.java
Expand Up @@ -248,7 +248,7 @@ public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) {
clientSettings.putAll(settings);
if (clientSettingsHandler != null) {
handlerContext.executeFromIO(() -> {
clientSettingsHandler.handle(clientSettings());
clientSettingsHandler.handle(remoteSettings());
});
}
}
Expand Down Expand Up @@ -429,18 +429,18 @@ public HttpConnection closeHandler(Handler<Void> handler) {
}

@Override
public HttpConnection clientSettingsHandler(Handler<io.vertx.core.http.Http2Settings> handler) {
public HttpConnection remoteSettingsHandler(Handler<io.vertx.core.http.Http2Settings> handler) {
clientSettingsHandler = handler;
return this;
}

@Override
public Handler<io.vertx.core.http.Http2Settings> clientSettingsHandler() {
public Handler<io.vertx.core.http.Http2Settings> remoteSettingsHandler() {
return clientSettingsHandler;
}

@Override
public io.vertx.core.http.Http2Settings clientSettings() {
public io.vertx.core.http.Http2Settings remoteSettings() {
return toVertxSettings(clientSettings);
}

Expand Down
8 changes: 1 addition & 7 deletions src/test/java/io/vertx/test/core/Http2ClientTest.java
Expand Up @@ -16,13 +16,7 @@

package io.vertx.test.core;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
import io.netty.handler.codec.http2.Http2Error;
import io.netty.handler.codec.http2.Http2Exception;
import io.netty.handler.codec.http2.Http2FrameAdapter;
import io.netty.handler.codec.http2.Http2Settings;
import io.vertx.core.Context;
import io.vertx.core.Future;
Expand Down Expand Up @@ -69,7 +63,7 @@ public void testClientSettings() throws Exception {
// Http2Settings updatedSettings = randomSettings();
// Future<Void> settingsRead = Future.future();
server.requestHandler(req -> {
io.vertx.core.http.Http2Settings settings = req.connection().clientSettings();
io.vertx.core.http.Http2Settings settings = req.connection().remoteSettings();
assertEquals(initialSettings.maxHeaderListSize(), settings.getMaxHeaderListSize());
assertEquals(initialSettings.maxFrameSize(), settings.getMaxFrameSize());
assertEquals(initialSettings.initialWindowSize(), settings.getInitialWindowSize());
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/io/vertx/test/core/Http2ServerTest.java
Expand Up @@ -30,7 +30,6 @@
import io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder;
import io.netty.handler.codec.http2.DefaultHttp2Connection;
import io.netty.handler.codec.http2.DefaultHttp2Headers;
import io.netty.handler.codec.http2.Http2CodecUtil;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
Expand Down Expand Up @@ -283,13 +282,13 @@ public void testClientSettings() throws Exception {
Http2Settings updatedSettings = randomSettings();
Future<Void> settingsRead = Future.future();
server.requestHandler(req -> {
io.vertx.core.http.Http2Settings settings = req.connection().clientSettings();
io.vertx.core.http.Http2Settings settings = req.connection().remoteSettings();
assertEquals(initialSettings.maxHeaderListSize(), settings.getMaxHeaderListSize());
assertEquals(initialSettings.maxFrameSize(), settings.getMaxFrameSize());
assertEquals(initialSettings.initialWindowSize(), settings.getInitialWindowSize());
assertEquals(initialSettings.maxConcurrentStreams(), settings.getMaxConcurrentStreams());
assertEquals((long) initialSettings.headerTableSize(), (long) settings.getHeaderTableSize());
req.connection().clientSettingsHandler(update -> {
req.connection().remoteSettingsHandler(update -> {
assertOnIOContext(ctx);
assertEquals(updatedSettings.maxHeaderListSize(), update.getMaxHeaderListSize());
assertEquals(updatedSettings.maxFrameSize(), update.getMaxFrameSize());
Expand Down

0 comments on commit 8ebf204

Please sign in to comment.