Skip to content

Commit a3214cb

Browse files
committed
Introduce HTTP connection SPI
1 parent 2f6b74b commit a3214cb

38 files changed

+405
-305
lines changed

vertx-core/src/main/java/io/vertx/core/http/HttpHeaders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import io.vertx.codegen.annotations.VertxGen;
2121
import io.vertx.core.MultiMap;
2222
import io.vertx.core.http.impl.headers.HeadersMultiMap;
23-
import io.vertx.core.http.impl.http2.Http2HeadersMultiMap;
23+
import io.vertx.core.http.impl.spi.Http2HeadersMultiMap;
2424

2525
/**
2626
* Contains a bunch of useful HTTP headers stuff:

vertx-core/src/main/java/io/vertx/core/http/impl/Http1xClientConnection.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public class Http1xClientConnection extends Http1xConnection implements HttpClie
7575
private final HostAndPort authority;
7676
public final ClientMetrics metrics;
7777
private final HttpVersion version;
78-
private final boolean pooled;
7978
private final long lifetimeEvictionTimestamp;
8079

8180
private final Deque<Stream> requests = new ArrayDeque<>();
@@ -102,7 +101,6 @@ public class Http1xClientConnection extends Http1xConnection implements HttpClie
102101
HostAndPort authority,
103102
ContextInternal context,
104103
ClientMetrics metrics,
105-
boolean pooled,
106104
long maxLifetime) {
107105
super(context, chctx);
108106
this.client = client;
@@ -115,7 +113,6 @@ public class Http1xClientConnection extends Http1xConnection implements HttpClie
115113
this.lifetimeEvictionTimestamp = maxLifetime > 0 ? System.currentTimeMillis() + maxLifetime : Long.MAX_VALUE;
116114
this.keepAliveTimeout = options.getKeepAliveTimeout();
117115
this.expirationTimestamp = expirationTimestampOf(keepAliveTimeout);
118-
this.pooled = pooled;
119116
}
120117

121118
@Override
@@ -151,11 +148,6 @@ public synchronized long activeStreams() {
151148
return requests.isEmpty() && responses.isEmpty() ? 0 : 1;
152149
}
153150

154-
@Override
155-
public boolean pooled() {
156-
return pooled;
157-
}
158-
159151
/**
160152
* @return a raw {@code NetSocket} - for internal use - must be called from event-loop
161153
*/

vertx-core/src/main/java/io/vertx/core/http/impl/Http1xServerConnection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ TracingPolicy tracingPolicy() {
129129
return tracingPolicy;
130130
}
131131

132+
@Override
133+
public HttpServerConnection streamHandler(Handler<HttpServerStream> handler) {
134+
// This feature is not available for HTTP/1.1
135+
return this;
136+
}
137+
132138
public HttpServerConnection handler(Handler<HttpServerRequest> handler) {
133139
requestHandler = handler;
134140
return this;

vertx-core/src/main/java/io/vertx/core/http/impl/Http2UpgradeClientConnection.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ public long concurrency() {
7979
return upgradeProcessed ? current.concurrency() : 1L;
8080
}
8181

82-
@Override
83-
public boolean pooled() {
84-
return current.pooled();
85-
}
86-
8782
@Override
8883
public long activeStreams() {
8984
return current.concurrency();
@@ -397,7 +392,7 @@ public void upgradeFailure(Throwable cause) {
397392
};
398393
upgrade.upgrade(upgradingStream, request, buf, end,
399394
upgradingConnection.channelHandlerContext().channel(),
400-
upgradingConnection.pooled(), blah
395+
blah
401396
);
402397
PromiseInternal<Void> promise = upgradingStream.context().promise();
403398
writeHead(request, chunked, buf, end, priority, connect, promise);
@@ -904,7 +899,6 @@ void upgrade(HttpClientStream upgradingStream,
904899
Buffer content,
905900
boolean end,
906901
Channel channel,
907-
boolean pooled,
908902
UpgradeResult result);
909903
}
910904
}

vertx-core/src/main/java/io/vertx/core/http/impl/HttpChannelConnector.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public class HttpChannelConnector {
6262
private final HttpVersion version;
6363
private final HostAndPort authority;
6464
private final SocketAddress server;
65-
private final boolean pooled;
6665
private final long maxLifetime;
6766
private final Http2ClientChannelInitializer http2ChannelInitializer;
6867

@@ -76,7 +75,6 @@ public HttpChannelConnector(HttpClientBase client,
7675
boolean useAlpn,
7776
HostAndPort authority,
7877
SocketAddress server,
79-
boolean pooled,
8078
long maxLifetimeMillis) {
8179

8280
Http2ClientChannelInitializer http2ChannelInitializer;
@@ -92,7 +90,7 @@ public HttpChannelConnector(HttpClientBase client,
9290
client.options.isDecompressionSupported(),
9391
client.options.getLogActivity());
9492
} else {
95-
http2ChannelInitializer = new Http2CodecClientChannelInitializer(client, metrics, pooled, maxLifetimeMillis, authority);
93+
http2ChannelInitializer = new Http2CodecClientChannelInitializer(client, metrics, maxLifetimeMillis, authority);
9694
}
9795

9896
this.client = client;
@@ -106,7 +104,6 @@ public HttpChannelConnector(HttpClientBase client,
106104
this.version = version;
107105
this.authority = authority;
108106
this.server = server;
109-
this.pooled = pooled;
110107
this.maxLifetime = maxLifetimeMillis;
111108
this.http2ChannelInitializer = http2ChannelInitializer;
112109
}
@@ -239,7 +236,7 @@ private void http1xConnected(HttpVersion version,
239236
boolean upgrade = version == HttpVersion.HTTP_2 && options.isHttp2ClearTextUpgrade();
240237
VertxHandler<Http1xClientConnection> clientHandler = VertxHandler.create(chctx -> {
241238
HttpClientMetrics met = client.metrics();
242-
Http1xClientConnection conn = new Http1xClientConnection(upgrade ? HttpVersion.HTTP_1_1 : version, client, chctx, ssl, server, authority, context, metrics, pooled, maxLifetime);
239+
Http1xClientConnection conn = new Http1xClientConnection(upgrade ? HttpVersion.HTTP_1_1 : version, client, chctx, ssl, server, authority, context, metrics, maxLifetime);
243240
if (met != null) {
244241
conn.metric(socketMetric);
245242
met.endpointConnected(metrics);

vertx-core/src/main/java/io/vertx/core/http/impl/HttpClientConnection.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public interface HttpClientConnection extends HttpConnection {
7373
*/
7474
HttpClientConnection concurrencyChangeHandler(Handler<Long> handler);
7575

76-
/**
77-
* @return whether the connection is pooled
78-
*/
79-
boolean pooled();
80-
8176
/**
8277
* @return the {@link ChannelHandlerContext} of the handler managing the connection
8378
*/

vertx-core/src/main/java/io/vertx/core/http/impl/HttpClientImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private Function<EndpointKey, SharedHttpClientConnectionGroup> httpEndpointProvi
137137
key = new EndpointKey(key.ssl, key.sslOptions, proxyOptions, server, key.authority);
138138
proxyOptions = null;
139139
}
140-
HttpChannelConnector connector = new HttpChannelConnector(HttpClientImpl.this, netClient, key.sslOptions, proxyOptions, clientMetrics, options.getProtocolVersion(), key.ssl, options.isUseAlpn(), key.authority, key.server, true, maxLifetime);
140+
HttpChannelConnector connector = new HttpChannelConnector(HttpClientImpl.this, netClient, key.sslOptions, proxyOptions, clientMetrics, options.getProtocolVersion(), key.ssl, options.isUseAlpn(), key.authority, key.server, maxLifetime);
141141
return new SharedHttpClientConnectionGroup(
142142
vertx,
143143
HttpClientImpl.this,
@@ -244,7 +244,6 @@ public Future<io.vertx.core.http.HttpClientConnection> connect(HttpConnectOption
244244
useAlpn,
245245
authority,
246246
server,
247-
false,
248247
0);
249248
return (Future) connector.httpConnect(vertx.getOrCreateContext()).map(conn -> new UnpooledHttpClientConnection(conn).init());
250249
}

vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
import io.vertx.core.Handler;
1515
import io.vertx.core.MultiMap;
1616
import io.vertx.core.http.HttpConnection;
17-
import io.vertx.core.http.HttpServerRequest;
18-
import io.vertx.core.http.impl.http2.Http2HeadersMultiMap;
1917
import io.vertx.core.internal.ContextInternal;
2018

2119
/**
2220
* @author <a href="mailto:[email protected]">Julien Viet</a>
2321
*/
2422
public interface HttpServerConnection extends HttpConnection {
2523

24+
HttpServerConnection streamHandler(Handler<HttpServerStream> handler);
25+
2626
MultiMap newHeaders();
2727

2828
boolean supportsSendFile();

vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerConnectionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import io.vertx.core.http.HttpServerRequest;
2424
import io.vertx.core.http.ServerWebSocket;
2525
import io.vertx.core.http.ServerWebSocketHandshake;
26-
import io.vertx.core.http.impl.http2.Http2ServerConnection;
26+
import io.vertx.core.http.impl.spi.HttpServerConnectionProvider;
2727
import io.vertx.core.internal.ContextInternal;
2828

2929
import java.util.ArrayList;
@@ -96,7 +96,7 @@ public void handle(HttpServerConnection conn) {
9696
http1Conn.handler(requestHandler);
9797
http1Conn.invalidRequestHandler(invalidRequestHandler);
9898
} else {
99-
Http2ServerConnection http2Conn = (Http2ServerConnection) conn;
99+
HttpServerConnectionProvider http2Conn = (HttpServerConnectionProvider) conn;
100100
http2Conn.streamHandler(stream -> {
101101
HttpServerOptions options = server.options;
102102
HttpServerRequestImpl request = new HttpServerRequestImpl(stream, stream.context(), options.isHandle100ContinueAutomatically(),

vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerConnectionInitializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public class HttpServerConnectionInitializer {
103103
compressionManager,
104104
streamContextSupplier,
105105
connectionHandler,
106-
serverOrigin,
107106
metric,
108107
options.getLogActivity()
109108
);

0 commit comments

Comments
 (0)