Skip to content

Commit

Permalink
Create flexible HttpServer protocol (h2, h2c, h1) implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Maldini committed Jul 6, 2018
1 parent cd69eba commit ca29e56
Show file tree
Hide file tree
Showing 8 changed files with 597 additions and 214 deletions.
48 changes: 48 additions & 0 deletions src/main/java/reactor/netty/http/HttpProtocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2011-2018 Pivotal Software Inc, All Rights Reserved.
*
* Licensed 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 reactor.netty.http;

/**
* An enum defining various Http negotiations between H2, H2c-upgrade,
* H2c-prior-knowledge and Http1.1
*
* @author Stephane Maldini
*/
public enum HttpProtocol {

/**
* The default supported HTTP protocol by HttpServer and HttpClient
*/
HTTP11,

/**
* HTTP 2.0 support with TLS
*/
H2,

/**
* HTTP 2.0 support with clear-text.
* <p>If used along with HTTP1 protocol, will support H2c "upgrade":
* Request or consume requests as HTTP 1.1 first, looking for HTTP 2.0 headers
* and {@literal Connection: Upgrade}. A server will typically reply a successful
* 101 status if upgrade is successful or a fallback http 1.1 response. When
* successful the client will start sending HTTP 2.0 traffic.
* <p>If used without HTTP1 protocol, will support H2c "prior-knowledge": Doesn't
* require {@literal Connection: Upgrade} handshake between a client and server but
* fallback to HTTP 1.1 will not be supported.
*/
H2C
}
13 changes: 12 additions & 1 deletion src/main/java/reactor/netty/http/server/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import reactor.netty.ConnectionObserver;
import reactor.netty.DisposableServer;
import reactor.netty.channel.BootstrapHandlers;
import reactor.netty.http.HttpProtocol;
import reactor.netty.tcp.SslProvider;
import reactor.netty.tcp.TcpServer;
import reactor.util.Logger;
Expand All @@ -50,7 +51,6 @@
* {@code
* HttpServer.create()
* .host("0.0.0.0")
* .secureSelfSigned()
* .handle((req, res) -> res.sendString(Flux.just("hello"))
* .bind()
* .block();
Expand Down Expand Up @@ -281,6 +281,17 @@ public final HttpServer observe(ConnectionObserver observer) {
return new HttpServerObserve(this, observer);
}

/**
* The HTTP protocol to support. Default is {@link HttpProtocol#HTTP11}.
*
* @param supportedProtocols The various {@link HttpProtocol} this server will support
*
* @return a new {@link HttpServer}
*/
public final HttpServer protocol(HttpProtocol... supportedProtocols) {
return tcpConfiguration(tcpServer -> tcpServer.bootstrap(b -> HttpServerConfiguration.protocols(b, supportedProtocols)));
}

/**
* The port to which this server should bind.
*
Expand Down
Loading

0 comments on commit ca29e56

Please sign in to comment.