Skip to content

Commit

Permalink
Server settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 13, 2016
1 parent de0e1fc commit 935ab5a
Show file tree
Hide file tree
Showing 10 changed files with 558 additions and 6 deletions.
21 changes: 21 additions & 0 deletions src/main/asciidoc/dataobjects.adoc
Expand Up @@ -247,6 +247,26 @@ Set the maximum number of worker threads to be used by the Vert.x instance.
+++ +++
|=== |===


[[Http2Settings]]
== Http2Settings

++++
HTTP2 settings.
++++
'''

[cols=">25%,^25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[enablePush]]`enablePush`|`Boolean`|-
|[[headerTableSize]]`headerTableSize`|`Number (Integer)`|-
|[[initialWindowSize]]`initialWindowSize`|`Number (Integer)`|-
|[[maxConcurrentStreams]]`maxConcurrentStreams`|`Number (Long)`|-
|[[maxFrameSize]]`maxFrameSize`|`Number (Integer)`|-
|[[maxHeaderListSize]]`maxHeaderListSize`|`Number (Integer)`|-
|===

[[Argument]] [[Argument]]
== Argument == Argument


Expand Down Expand Up @@ -923,6 +943,7 @@ Set whether 100 Continue should be handled automatically
+++ +++
Set the host Set the host
+++ +++
|[[http2Settings]]`http2Settings`|`link:dataobjects.html#Http2Settings[Http2Settings]`|-
|[[idleTimeout]]`idleTimeout`|`Number (int)`| |[[idleTimeout]]`idleTimeout`|`Number (int)`|
+++ +++
Set the idle timeout, in seconds. zero means don't timeout. Set the idle timeout, in seconds. zero means don't timeout.
Expand Down
70 changes: 70 additions & 0 deletions src/main/generated/io/vertx/core/http/Http2SettingsConverter.java
@@ -0,0 +1,70 @@
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.vertx.core.http;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

/**
* Converter for {@link io.vertx.core.http.Http2Settings}.
*
* NOTE: This class has been automatically generated from the {@link io.vertx.core.http.Http2Settings} original class using Vert.x codegen.
*/
public class Http2SettingsConverter {

public static void fromJson(JsonObject json, Http2Settings obj) {
if (json.getValue("enablePush") instanceof Boolean) {
obj.setEnablePush((Boolean)json.getValue("enablePush"));
}
if (json.getValue("headerTableSize") instanceof Number) {
obj.setHeaderTableSize(((Number)json.getValue("headerTableSize")).intValue());
}
if (json.getValue("initialWindowSize") instanceof Number) {
obj.setInitialWindowSize(((Number)json.getValue("initialWindowSize")).intValue());
}
if (json.getValue("maxConcurrentStreams") instanceof Number) {
obj.setMaxConcurrentStreams(((Number)json.getValue("maxConcurrentStreams")).longValue());
}
if (json.getValue("maxFrameSize") instanceof Number) {
obj.setMaxFrameSize(((Number)json.getValue("maxFrameSize")).intValue());
}
if (json.getValue("maxHeaderListSize") instanceof Number) {
obj.setMaxHeaderListSize(((Number)json.getValue("maxHeaderListSize")).intValue());
}
}

public static void toJson(Http2Settings obj, JsonObject json) {
if (obj.getEnablePush() != null) {
json.put("enablePush", obj.getEnablePush());
}
if (obj.getHeaderTableSize() != null) {
json.put("headerTableSize", obj.getHeaderTableSize());
}
if (obj.getInitialWindowSize() != null) {
json.put("initialWindowSize", obj.getInitialWindowSize());
}
if (obj.getMaxConcurrentStreams() != null) {
json.put("maxConcurrentStreams", obj.getMaxConcurrentStreams());
}
if (obj.getMaxFrameSize() != null) {
json.put("maxFrameSize", obj.getMaxFrameSize());
}
if (obj.getMaxHeaderListSize() != null) {
json.put("maxHeaderListSize", obj.getMaxHeaderListSize());
}
}
}
Expand Up @@ -33,6 +33,9 @@ public static void fromJson(JsonObject json, HttpServerOptions obj) {
if (json.getValue("handle100ContinueAutomatically") instanceof Boolean) { if (json.getValue("handle100ContinueAutomatically") instanceof Boolean) {
obj.setHandle100ContinueAutomatically((Boolean)json.getValue("handle100ContinueAutomatically")); obj.setHandle100ContinueAutomatically((Boolean)json.getValue("handle100ContinueAutomatically"));
} }
if (json.getValue("http2Settings") instanceof JsonObject) {
obj.setHttp2Settings(new io.vertx.core.http.Http2Settings((JsonObject)json.getValue("http2Settings")));
}
if (json.getValue("maxChunkSize") instanceof Number) { if (json.getValue("maxChunkSize") instanceof Number) {
obj.setMaxChunkSize(((Number)json.getValue("maxChunkSize")).intValue()); obj.setMaxChunkSize(((Number)json.getValue("maxChunkSize")).intValue());
} }
Expand All @@ -53,6 +56,9 @@ public static void fromJson(JsonObject json, HttpServerOptions obj) {
public static void toJson(HttpServerOptions obj, JsonObject json) { public static void toJson(HttpServerOptions obj, JsonObject json) {
json.put("compressionSupported", obj.isCompressionSupported()); json.put("compressionSupported", obj.isCompressionSupported());
json.put("handle100ContinueAutomatically", obj.isHandle100ContinueAutomatically()); json.put("handle100ContinueAutomatically", obj.isHandle100ContinueAutomatically());
if (obj.getHttp2Settings() != null) {
json.put("http2Settings", obj.getHttp2Settings().toJson());
}
json.put("maxChunkSize", obj.getMaxChunkSize()); json.put("maxChunkSize", obj.getMaxChunkSize());
json.put("maxHeaderSize", obj.getMaxHeaderSize()); json.put("maxHeaderSize", obj.getMaxHeaderSize());
json.put("maxInitialLineLength", obj.getMaxInitialLineLength()); json.put("maxInitialLineLength", obj.getMaxInitialLineLength());
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/io/vertx/core/http/Http2Settings.java
@@ -0,0 +1,134 @@
/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/

package io.vertx.core.http;

import io.netty.handler.codec.http2.Http2CodecUtil;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.impl.Arguments;
import io.vertx.core.json.JsonObject;

/**
* HTTP2 settings.
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
@DataObject(generateConverter = true)
public class Http2Settings {

private Integer headerTableSize;
private Boolean enablePush;
private Long maxConcurrentStreams;
private Integer initialWindowSize;
private Integer maxFrameSize;
private Integer maxHeaderListSize;

public Http2Settings() {
}

public Http2Settings(JsonObject json) {
Http2SettingsConverter.fromJson(json, this);
}

public Http2Settings(Http2Settings that) {
headerTableSize = that.headerTableSize;
enablePush = that.enablePush;
maxConcurrentStreams = that.maxConcurrentStreams;
initialWindowSize = that.initialWindowSize;
maxFrameSize = that.maxFrameSize;
maxHeaderListSize = that.maxHeaderListSize;
}

public Integer getHeaderTableSize() {
return headerTableSize;
}

public Http2Settings setHeaderTableSize(Integer headerTableSize) {
Arguments.require(headerTableSize == null || headerTableSize >= Http2CodecUtil.MIN_HEADER_TABLE_SIZE,
"headerTableSize must be >= " + Http2CodecUtil.MIN_HEADER_TABLE_SIZE);
Arguments.require(headerTableSize == null || headerTableSize < Http2CodecUtil.MAX_HEADER_TABLE_SIZE,
"headerTableSize must be <= " + Http2CodecUtil.MAX_HEADER_TABLE_SIZE);
this.headerTableSize = headerTableSize;
return this;
}

public Boolean getEnablePush() {
return enablePush;
}

public Http2Settings setEnablePush(Boolean enablePush) {
this.enablePush = enablePush;
return this;
}

public Long getMaxConcurrentStreams() {
return maxConcurrentStreams;
}

public Http2Settings setMaxConcurrentStreams(Long maxConcurrentStreams) {
Arguments.require(maxConcurrentStreams == null || maxConcurrentStreams >= Http2CodecUtil.MIN_CONCURRENT_STREAMS,
"maxConcurrentStreams must be >= " + Http2CodecUtil.MIN_CONCURRENT_STREAMS);
Arguments.require(maxConcurrentStreams == null || maxConcurrentStreams <= Http2CodecUtil.MAX_CONCURRENT_STREAMS,
"maxConcurrentStreams must be < " + Http2CodecUtil.MAX_CONCURRENT_STREAMS);
this.maxConcurrentStreams = maxConcurrentStreams;
return this;
}

public Integer getInitialWindowSize() {
return initialWindowSize;
}

public Http2Settings setInitialWindowSize(Integer initialWindowSize) {
Arguments.require(initialWindowSize == null || initialWindowSize >= Http2CodecUtil.MIN_INITIAL_WINDOW_SIZE,
"initialWindowSize must be >= " + Http2CodecUtil.MIN_INITIAL_WINDOW_SIZE);
Arguments.require(initialWindowSize == null || initialWindowSize < Http2CodecUtil.MAX_INITIAL_WINDOW_SIZE,
"initialWindowSize must be < " + Http2CodecUtil.MAX_INITIAL_WINDOW_SIZE);
this.initialWindowSize = initialWindowSize;
return this;
}

public Integer getMaxFrameSize() {
return maxFrameSize;
}

public Http2Settings setMaxFrameSize(Integer maxFrameSize) {
Arguments.require(maxFrameSize == null || maxFrameSize >= Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND,
"maxFrameSize must be >= " + Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);
Arguments.require(maxFrameSize == null || maxFrameSize <= Http2CodecUtil.MAX_FRAME_SIZE_UPPER_BOUND,
"maxFrameSize must be <= " + Http2CodecUtil.MAX_FRAME_SIZE_UPPER_BOUND);
this.maxFrameSize = maxFrameSize;
return this;
}

public Integer getMaxHeaderListSize() {
return maxHeaderListSize;
}

public Http2Settings setMaxHeaderListSize(Integer maxHeaderListSize) {
Arguments.require(maxHeaderListSize == null || maxHeaderListSize >= Http2CodecUtil.MIN_HEADER_LIST_SIZE,
"maxHeaderListSize must be >= " + Http2CodecUtil.MIN_HEADER_LIST_SIZE);
Arguments.require(maxHeaderListSize == null || maxHeaderListSize <= Http2CodecUtil.MAX_HEADER_LIST_SIZE,
"maxHeaderListSize must be <= " + Http2CodecUtil.MAX_HEADER_LIST_SIZE);
this.maxHeaderListSize = maxHeaderListSize;
return this;
}

public JsonObject toJson() {
JsonObject json = new JsonObject();
Http2SettingsConverter.toJson(this, json);
return json;
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/vertx/core/http/HttpConnection.java
Expand Up @@ -17,7 +17,9 @@
package io.vertx.core.http; package io.vertx.core.http;


import io.vertx.codegen.annotations.Fluent; import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen; import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler; import io.vertx.core.Handler;


/** /**
Expand All @@ -44,4 +46,50 @@ public interface HttpConnection {
@Fluent @Fluent
HttpConnection closeHandler(Handler<Void> handler); HttpConnection closeHandler(Handler<Void> handler);


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

/**
* Send to the client an update of the server settings.
*
* @param settings the new settings
* @return a reference to this, so the API can be used fluently
*/
@Fluent
HttpConnection updateSettings(Http2Settings settings);

/**
* Send to the client an update of the server settings.<p/>
*
* The {@code completionHandler} will be notified when the client has acknowledged the settings.
*
* @param settings the new settings
* @param completionHandler the handler notified when the settings have been acked by the client
* @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
*/
Http2Settings clientSettings();

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

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

} }
11 changes: 11 additions & 0 deletions src/main/java/io/vertx/core/http/HttpServerOptions.java
Expand Up @@ -71,6 +71,7 @@ public class HttpServerOptions extends NetServerOptions {
private int maxChunkSize; private int maxChunkSize;
private int maxInitialLineLength; private int maxInitialLineLength;
private int maxHeaderSize; private int maxHeaderSize;
private Http2Settings http2Settings;


/** /**
* Default constructor * Default constructor
Expand All @@ -95,6 +96,7 @@ public HttpServerOptions(HttpServerOptions other) {
this.maxChunkSize = other.getMaxChunkSize(); this.maxChunkSize = other.getMaxChunkSize();
this.maxInitialLineLength = other.getMaxInitialLineLength(); this.maxInitialLineLength = other.getMaxInitialLineLength();
this.maxHeaderSize = other.getMaxHeaderSize(); this.maxHeaderSize = other.getMaxHeaderSize();
this.http2Settings = other.http2Settings != null ? new Http2Settings(other.http2Settings) : null;
} }


/** /**
Expand Down Expand Up @@ -393,6 +395,15 @@ public HttpServerOptions setMaxHeaderSize(int maxHeaderSize) {
return this; return this;
} }


public Http2Settings getHttp2Settings() {
return http2Settings;
}

public HttpServerOptions setHttp2Settings(Http2Settings http2Settings) {
this.http2Settings = http2Settings;
return this;
}

@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/http/impl/HttpServerImpl.java
Expand Up @@ -203,7 +203,7 @@ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) thr
if (protocol.equals("http/1.1")) { if (protocol.equals("http/1.1")) {
configureHttp1(pipeline); configureHttp1(pipeline);
} else { } else {
pipeline.addLast("handler", new VertxHttp2HandlerBuilder(vertx, serverOrigin, requestStream.handler()).build()); pipeline.addLast("handler", new VertxHttp2HandlerBuilder(ctx, vertx, serverOrigin, options.getHttp2Settings(), requestStream.handler()).build());
} }
} }
}); });
Expand Down

0 comments on commit 935ab5a

Please sign in to comment.