Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 13, 2016
1 parent b81a9a5 commit 835322d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 74 deletions.
Expand Up @@ -359,7 +359,7 @@ public void reset(long code) {
}

private HttpRequest createRequest(HttpVersion version, HttpMethod method, String uri, MultiMap headers) {
DefaultHttpRequest request = new DefaultHttpRequest(UriUtils.toNettyHttpVersion(version), UriUtils.toNettyHttpMethod(method), uri, false);
DefaultHttpRequest request = new DefaultHttpRequest(HttpUtils.toNettyHttpVersion(version), HttpUtils.toNettyHttpMethod(method), uri, false);
if (headers != null) {
for (Map.Entry<String, String> header : headers) {
// Todo : multi valued headers
Expand Down
Expand Up @@ -285,7 +285,7 @@ public HttpVersion version() {
public HttpMethod method() {
if (method == null) {
String sMethod = headers.method().toString();
method = UriUtils.toVertxMethod(sMethod);
method = HttpUtils.toVertxMethod(sMethod);
}
return method;
}
Expand All @@ -312,7 +312,7 @@ public String uri() {
if (path == null) {
CharSequence path = headers.path();
if (path != null) {
this.path = UriUtils.parsePath(path.toString());
this.path = HttpUtils.parsePath(path.toString());
}
}
return path;
Expand All @@ -323,7 +323,7 @@ public String uri() {
if (query == null) {
CharSequence path = headers.path();
if (path != null) {
this.query = UriUtils.parseQuery(path.toString());
this.query = HttpUtils.parseQuery(path.toString());
}
}
return query;
Expand Down Expand Up @@ -367,7 +367,7 @@ public String getHeader(CharSequence headerName) {
@Override
public MultiMap params() {
if (params == null) {
params = UriUtils.params(uri());
params = HttpUtils.params(uri());
}
return params;
}
Expand Down Expand Up @@ -399,7 +399,7 @@ public String absoluteURI() {
}
if (absoluteURI == null) {
try {
absoluteURI = UriUtils.absoluteURI(serverOrigin, this);
absoluteURI = HttpUtils.absoluteURI(serverOrigin, this);
} catch (URISyntaxException e) {
log.error("Failed to create abs uri", e);
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java
Expand Up @@ -28,8 +28,6 @@
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
import io.netty.util.CharsetUtil;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
Expand Down Expand Up @@ -139,15 +137,15 @@ public String uri() {
@Override
public String path() {
if (path == null) {
path = UriUtils.parsePath(uri());
path = HttpUtils.parsePath(uri());
}
return path;
}

@Override
public String query() {
if (query == null) {
query = UriUtils.parseQuery(uri());
query = HttpUtils.parseQuery(uri());
}
return query;
}
Expand Down Expand Up @@ -183,7 +181,7 @@ public String getHeader(CharSequence headerName) {
@Override
public MultiMap params() {
if (params == null) {
params = UriUtils.params(uri());
params = HttpUtils.params(uri());
}
return params;
}
Expand Down Expand Up @@ -254,7 +252,7 @@ public SocketAddress remoteAddress() {
public String absoluteURI() {
if (absoluteURI == null) {
try {
absoluteURI = UriUtils.absoluteURI(conn.getServerOrigin(), this);
absoluteURI = HttpUtils.absoluteURI(conn.getServerOrigin(), this);
} catch (URISyntaxException e) {
log.error("Failed to create abs uri", e);
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.handler.codec.http2.Http2Headers;
import io.netty.handler.codec.http2.Http2Settings;
import io.vertx.core.MultiMap;
import io.vertx.core.http.CaseInsensitiveHeaders;
import io.vertx.core.http.HttpServerRequest;
Expand All @@ -33,13 +34,13 @@
import java.util.Map;

/**
* Various uri utils.
* Various http utils.
*
* @author <a href="mailto:nmaurer@redhat.com">Norman Maurer</a>
*/
final class UriUtils {
public final class HttpUtils {

private UriUtils() {
private HttpUtils() {
}

/**
Expand Down Expand Up @@ -111,6 +112,42 @@ static MultiMap params(String uri) {
return params;
}

public static Http2Settings fromVertxSettings(io.vertx.core.http.Http2Settings settings) {
Http2Settings converted = new Http2Settings();
if (settings.getEnablePush() != null) {
converted.pushEnabled(settings.getEnablePush());
}
if (settings.getMaxConcurrentStreams() != null) {
converted.maxConcurrentStreams(settings.getMaxConcurrentStreams());
}
if (settings.getMaxHeaderListSize() != null) {
converted.maxHeaderListSize(settings.getMaxHeaderListSize());
}
if (settings.getMaxFrameSize() != null) {
converted.maxFrameSize(settings.getMaxFrameSize());
}
if (settings.getInitialWindowSize() != null) {
converted.initialWindowSize(settings.getInitialWindowSize());
}
if (settings.getHeaderTableSize() != null) {
converted.headerTableSize((int)(long)settings.getHeaderTableSize());
}
return converted;
}

public static io.vertx.core.http.Http2Settings toVertxSettings(Http2Settings settings) {
io.vertx.core.http.Http2Settings converted = new io.vertx.core.http.Http2Settings();
converted.setEnablePush(settings.pushEnabled());
converted.setMaxConcurrentStreams(settings.maxConcurrentStreams());
converted.setMaxHeaderListSize(settings.maxHeaderListSize());
converted.setMaxFrameSize(settings.maxFrameSize());
converted.setInitialWindowSize(settings.initialWindowSize());
if (settings.headerTableSize() != null) {
converted.setHeaderTableSize((int)(long)settings.headerTableSize());
}
return converted;
}

private static class CustomCompressor extends HttpContentCompressor {
@Override
public ZlibWrapper determineWrapper(String acceptEncoding) {
Expand Down
Expand Up @@ -31,12 +31,10 @@
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.VertxException;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.CaseInsensitiveHeaders;
import io.vertx.core.http.HttpConnection;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.StreamResetException;
Expand Down Expand Up @@ -160,7 +158,7 @@ public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorC
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
Http2ClientStream stream = streams.get(streamId);
HttpMethod method = UriUtils.toVertxMethod(headers.method().toString());
HttpMethod method = HttpUtils.toVertxMethod(headers.method().toString());
String uri = headers.path().toString();
String host = headers.authority() != null ? headers.authority().toString() : null;
MultiMap headersMap = new Http2HeadersAdaptor(headers);
Expand Down
Expand Up @@ -280,12 +280,12 @@ public Handler<io.vertx.core.http.Http2Settings> remoteSettingsHandler() {

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

@Override
public io.vertx.core.http.Http2Settings settings() {
return toVertxSettings(serverSettings);
return HttpUtils.toVertxSettings(serverSettings);
}

@Override
Expand All @@ -296,7 +296,7 @@ public HttpConnection updateSettings(io.vertx.core.http.Http2Settings settings)
@Override
public HttpConnection updateSettings(io.vertx.core.http.Http2Settings settings, @Nullable Handler<AsyncResult<Void>> completionHandler) {
Context completionContext = completionHandler != null ? context.owner().getOrCreateContext() : null;
Http2Settings settingsUpdate = fromVertxSettings(settings);
Http2Settings settingsUpdate = HttpUtils.fromVertxSettings(settings);
settingsUpdate.remove(Http2CodecUtil.SETTINGS_ENABLE_PUSH);
encoder().writeSettings(handlerCtx, settingsUpdate, handlerCtx.newPromise()).addListener(fut -> {
if (fut.isSuccess()) {
Expand Down Expand Up @@ -348,39 +348,4 @@ private void checkShutdownHandler() {
}
}

public static Http2Settings fromVertxSettings(io.vertx.core.http.Http2Settings settings) {
Http2Settings converted = new Http2Settings();
if (settings.getEnablePush() != null) {
converted.pushEnabled(settings.getEnablePush());
}
if (settings.getMaxConcurrentStreams() != null) {
converted.maxConcurrentStreams(settings.getMaxConcurrentStreams());
}
if (settings.getMaxHeaderListSize() != null) {
converted.maxHeaderListSize(settings.getMaxHeaderListSize());
}
if (settings.getMaxFrameSize() != null) {
converted.maxFrameSize(settings.getMaxFrameSize());
}
if (settings.getInitialWindowSize() != null) {
converted.initialWindowSize(settings.getInitialWindowSize());
}
if (settings.getHeaderTableSize() != null) {
converted.headerTableSize((int)(long)settings.getHeaderTableSize());
}
return converted;
}

public static io.vertx.core.http.Http2Settings toVertxSettings(Http2Settings settings) {
io.vertx.core.http.Http2Settings converted = new io.vertx.core.http.Http2Settings();
converted.setEnablePush(settings.pushEnabled());
converted.setMaxConcurrentStreams(settings.maxConcurrentStreams());
converted.setMaxHeaderListSize(settings.maxHeaderListSize());
converted.setMaxFrameSize(settings.maxFrameSize());
converted.setInitialWindowSize(settings.initialWindowSize());
if (settings.headerTableSize() != null) {
converted.setHeaderTableSize((int)(long)settings.headerTableSize());
}
return converted;
}
}
Expand Up @@ -146,7 +146,7 @@ public void onHeadersRead(ChannelHandlerContext ctx, int streamId,
Http2Stream stream = conn.stream(streamId);
Http2ServerRequestImpl req = (Http2ServerRequestImpl) streams.get(streamId);
if (req == null) {
String contentEncoding = options.isCompressionSupported() ? UriUtils.determineContentEncoding(headers) : null;
String contentEncoding = options.isCompressionSupported() ? HttpUtils.determineContentEncoding(headers) : null;
Http2ServerRequestImpl newReq = req = new Http2ServerRequestImpl(context.owner(), this, serverOrigin, conn, stream, ctx, encoder(), headers, contentEncoding);
if (isMalformedRequest(headers)) {
encoder().writeRstStream(ctx, streamId, Http2Error.PROTOCOL_ERROR.code(), ctx.newPromise());
Expand Down Expand Up @@ -253,7 +253,7 @@ void sendPush(int streamId, Http2Headers headers, Handler<AsyncResult<HttpServer
int promisedStreamId = connection().local().incrementAndGetNextStreamId();
encoder().writePushPromise(handlerCtx, streamId, promisedStreamId, headers, 0, handlerCtx.newPromise()).addListener(fut -> {
if (fut.isSuccess()) {
String contentEncoding = UriUtils.determineContentEncoding(headers);
String contentEncoding = HttpUtils.determineContentEncoding(headers);
schedulePush(handlerCtx, promisedStreamId, contentEncoding, handler);
} else {
context.executeFromIO(() -> {
Expand Down
14 changes: 2 additions & 12 deletions src/test/java/io/vertx/test/core/Http2ClientTest.java
Expand Up @@ -16,21 +16,16 @@

package io.vertx.test.core;

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
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.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
import io.netty.handler.codec.http2.Http2ConnectionHandler;
Expand All @@ -54,6 +49,7 @@
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.StreamResetException;
import io.vertx.core.http.impl.HttpUtils;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.JksOptions;
import io.vertx.core.net.SocketAddress;
Expand Down Expand Up @@ -116,13 +112,7 @@ public void testClientSettings() throws Exception {
});
startServer();
client.close();
client = vertx.createHttpClient(clientOptions.setHttp2Settings(new io.vertx.core.http.Http2Settings().
setEnablePush(initialSettings.pushEnabled()).
setHeaderTableSize((int)(long)initialSettings.headerTableSize()).
setInitialWindowSize(initialSettings.initialWindowSize()).
setMaxConcurrentStreams(initialSettings.maxConcurrentStreams()).
setMaxFrameSize(initialSettings.maxFrameSize()).
setMaxHeaderListSize(initialSettings.maxHeaderListSize())));
client = vertx.createHttpClient(clientOptions.setHttp2Settings(HttpUtils.toVertxSettings(initialSettings)));
client.getNow(4043, "localhost", "/somepath", resp -> {
testComplete();
});
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/vertx/test/core/Http2ServerTest.java
Expand Up @@ -57,7 +57,7 @@
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.StreamResetException;
import io.vertx.core.http.impl.VertxHttp2ServerHandler;
import io.vertx.core.http.impl.HttpUtils;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.impl.KeyStoreHelper;
import io.vertx.core.net.impl.SSLHelper;
Expand Down Expand Up @@ -215,7 +215,7 @@ public void testConnectionHandler() throws Exception {
public void testServerInitialSettings() throws Exception {
Http2Settings settings = randomSettings();
server.close();
server = vertx.createHttpServer(serverOptions.setHttp2Settings(VertxHttp2ServerHandler.toVertxSettings(settings)));
server = vertx.createHttpServer(serverOptions.setHttp2Settings(HttpUtils.toVertxSettings(settings)));
server.requestHandler(req -> fail());
startServer();
TestClient client = new TestClient();
Expand Down Expand Up @@ -248,7 +248,7 @@ public void testServerSettings() throws Exception {
Context otherContext = vertx.getOrCreateContext();
server.connectionHandler(conn -> {
otherContext.runOnContext(v -> {
conn.updateSettings(VertxHttp2ServerHandler.toVertxSettings(expectedSettings), ar -> {
conn.updateSettings(HttpUtils.toVertxSettings(expectedSettings), ar -> {
assertSame(otherContext, Vertx.currentContext());
io.vertx.core.http.Http2Settings ackedSettings = conn.settings();
assertEquals(expectedSettings.maxHeaderListSize(), ackedSettings.getMaxHeaderListSize());
Expand Down Expand Up @@ -1197,7 +1197,7 @@ private void testHandlerFailure(boolean data, BiConsumer<RuntimeException, HttpS
RuntimeException failure = new RuntimeException();
Http2Settings settings = randomSettings();
server.close();
server = vertx.createHttpServer(serverOptions.setHttp2Settings(VertxHttp2ServerHandler.toVertxSettings(settings)));
server = vertx.createHttpServer(serverOptions.setHttp2Settings(HttpUtils.toVertxSettings(settings)));
configurator.accept(failure, server);
Context ctx = vertx.getOrCreateContext();
ctx.exceptionHandler(err -> {
Expand Down

0 comments on commit 835322d

Please sign in to comment.