Skip to content

Commit 785b9cf

Browse files
committed
Add HttpConnection#protocolVersion to indicate the version of the HTTP protocol of a connection.
1 parent dc85931 commit 785b9cf

File tree

7 files changed

+48
-0
lines changed

7 files changed

+48
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
@VertxGen
4040
public interface HttpConnection {
4141

42+
/**
43+
* @return the version of the protocol of this connection
44+
*/
45+
HttpVersion protocolVersion();
46+
4247
/**
4348
* @return the current connection window size or {@code -1} for HTTP/1.x
4449
*/

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public HttpConnection setWindowSize(int windowSize) {
8989
return actual.setWindowSize(windowSize);
9090
}
9191

92+
@Override
93+
public HttpVersion protocolVersion() {
94+
return actual.protocolVersion();
95+
}
96+
9297
@Override
9398
@Fluent
9499
public HttpConnection goAway(long errorCode) {

vertx-core/src/main/java/io/vertx/core/http/impl/http1x/Http1xConnection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.vertx.core.http.GoAway;
2828
import io.vertx.core.http.Http2Settings;
2929
import io.vertx.core.http.HttpConnection;
30+
import io.vertx.core.http.HttpVersion;
3031
import io.vertx.core.internal.ContextInternal;
3132
import io.vertx.core.net.impl.VertxConnection;
3233

@@ -94,6 +95,11 @@ public Http1xConnection closeHandler(Handler<Void> handler) {
9495
return (Http1xConnection) super.closeHandler(handler);
9596
}
9697

98+
@Override
99+
public HttpVersion protocolVersion() {
100+
return HttpVersion.HTTP_1_1;
101+
}
102+
97103
@Override
98104
public Http1xConnection exceptionHandler(Handler<Throwable> handler) {
99105
return (Http1xConnection) super.exceptionHandler(handler);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ public HttpClientConnection alternativeServicesHandler(Handler<String> handler)
821821
return this;
822822
}
823823

824+
@Override
825+
public HttpVersion protocolVersion() {
826+
return current.protocolVersion();
827+
}
828+
824829
@Override
825830
public HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData) {
826831
return current.goAway(errorCode, lastStreamId, debugData);

vertx-core/src/main/java/io/vertx/core/http/impl/http2/codec/Http2ConnectionImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.vertx.core.Promise;
2929
import io.vertx.core.VertxException;
3030
import io.vertx.core.buffer.Buffer;
31+
import io.vertx.core.http.HttpVersion;
3132
import io.vertx.core.http.impl.HttpUtils;
3233
import io.vertx.core.http.impl.http2.Http2Connection;
3334
import io.vertx.core.http.impl.http2.Http2Stream;
@@ -337,6 +338,11 @@ public HttpConnection setWindowSize(int windowSize) {
337338
}
338339
}
339340

341+
@Override
342+
public HttpVersion protocolVersion() {
343+
return HttpVersion.HTTP_2;
344+
}
345+
340346
@Override
341347
public HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData) {
342348
if (errorCode < 0) {

vertx-core/src/main/java/io/vertx/core/http/impl/http2/multiplex/Http2MultiplexConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public void writePriorityFrame(int streamId, StreamPriority priority, Promise<Vo
202202
promise.fail("Unsupported");
203203
}
204204

205+
@Override
206+
public HttpVersion protocolVersion() {
207+
return HttpVersion.HTTP_2;
208+
}
209+
205210
@Override
206211
public HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData) {
207212
handler.writeGoAway(errorCode, debugData != null ? ((BufferInternal)debugData).getByteBuf() : Unpooled.EMPTY_BUFFER, context.promise());

vertx-core/src/test/java/io/vertx/tests/http/HttpTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6441,4 +6441,20 @@ public void testServerShutdown() throws Exception {
64416441
fut.await();
64426442
assertTrue((System.currentTimeMillis() - now) < timeout / 4);
64436443
}
6444+
6445+
@Test
6446+
public void testConnectionVersion() throws Exception {
6447+
server.requestHandler(request -> {
6448+
assertEquals(request.version(), request.connection().protocolVersion());
6449+
request.response().end();
6450+
});
6451+
startServer(testAddress);
6452+
client.request(requestOptions)
6453+
.compose(req -> req
6454+
.send()
6455+
.expecting(HttpResponseExpectation.SC_OK)
6456+
.compose(HttpClientResponse::end))
6457+
.await();
6458+
}
6459+
64446460
}

0 commit comments

Comments
 (0)