Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<wildfly-elytron.version>2.6.3.Final</wildfly-elytron.version>
<jboss-marshalling.version>2.2.2.Final</jboss-marshalling.version>
<jboss-threads.version>3.8.0.Final</jboss-threads.version>
<vertx.version>4.5.20</vertx.version>
<vertx.version>4.5.21</vertx.version>
<httpclient.version>4.5.14</httpclient.version>
<httpcore.version>4.4.16</httpcore.version>
<httpasync.version>4.1.5</httpasync.version>
Expand All @@ -132,7 +132,7 @@
<infinispan.version>15.0.19.Final</infinispan.version>
<infinispan.protostream.version>5.0.13.Final</infinispan.protostream.version>
<caffeine.version>3.2.0</caffeine.version>
<netty.version>4.1.124.Final</netty.version>
<netty.version>4.1.127.Final</netty.version>
<brotli4j.version>1.16.0</brotli4j.version>
<reactive-streams.version>1.0.4</reactive-streams.version>
<jboss-logging.version>3.6.1.Final</jboss-logging.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ public HostAndPort authority() {
return forwardedParser.authority();
}

@Override
public HostAndPort authority(boolean real) {
if (real) {
return delegate.authority();
}
return this.authority();
}

@Override
public boolean isValidAuthority() {
return forwardedParser.authority() != null;
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

<mutiny.version>2.9.4</mutiny.version>
<smallrye-common.version>2.12.0</smallrye-common.version>
<vertx.version>4.5.20</vertx.version>
<vertx.version>4.5.21</vertx.version>
<rest-assured.version>5.5.1</rest-assured.version>
<commons-logging-jboss-logging.version>1.0.0.Final</commons-logging-jboss-logging.version>
<jackson-bom.version>2.18.2</jackson-bom.version>
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/vertx-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<jboss-logging.version>3.6.1.Final</jboss-logging.version>
<vertx.version>4.5.20</vertx.version>
<vertx.version>4.5.21</vertx.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,87 +62,98 @@ public static void runCompressorsTest(String endpoint, String acceptEncoding, St
// Why not use RestAssured? Because it doesn't let you configure Accept-Encoding easily
// and when it comes to Brotli, not at all.
// No, given().header("Accept-Encoding", acceptEncoding) doesn't cut it.
final WebClient client = WebClient.create(Vertx.vertx(), new WebClientOptions()
.setLogActivity(true)
.setFollowRedirects(true)
// Vert.x Web Client
// -----------------
// Why not use the client's built-in decompression support?
// Why you do decompression manually here?
// Because it then removes the original content-encoding header,
// and it fakes in a transfer-encoding header the server has never sent. Sad.
// RestAssured didn't let us configure Accept-Encoding easily, but at least
// it didn't mess with the response headers.
.setDecompressionSupported(false));
final CompletableFuture<HttpResponse<Buffer>> future = new CompletableFuture<>();
client.requestAbs(HttpMethod.GET, endpoint)
.putHeader(HttpHeaders.ACCEPT_ENCODING.toString(), acceptEncoding)
.putHeader(HttpHeaders.ACCEPT.toString(), "*/*")
.putHeader(HttpHeaders.USER_AGENT.toString(), "Tester")
.send(ar -> {
if (ar.succeeded()) {
future.complete(ar.result());
} else {
future.completeExceptionally(ar.cause());
}
});
Vertx vertx = Vertx.vertx();
try {
final HttpResponse<Buffer> response = future.get();
final String actualEncoding = response.headers().get("content-encoding");
final WebClient client = WebClient.create(vertx, new WebClientOptions()
.setLogActivity(true)
.setFollowRedirects(true)
// Vert.x Web Client
// -----------------
// Why not use the client's built-in decompression support?
// Why you do decompression manually here?
// Because it then removes the original content-encoding header,
// and it fakes in a transfer-encoding header the server has never sent. Sad.
// RestAssured didn't let us configure Accept-Encoding easily, but at least
// it didn't mess with the response headers.
.setDecompressionSupported(false));
final CompletableFuture<HttpResponse<Buffer>> future = new CompletableFuture<>();
client.requestAbs(HttpMethod.GET, endpoint)
.putHeader(HttpHeaders.ACCEPT_ENCODING.toString(), acceptEncoding)
.putHeader(HttpHeaders.ACCEPT.toString(), "*/*")
.putHeader(HttpHeaders.USER_AGENT.toString(), "Tester")
.send(ar -> {
if (ar.succeeded()) {
future.complete(ar.result());
} else {
future.completeExceptionally(ar.cause());
}
});
try {
final HttpResponse<Buffer> response = future.get();
final String actualEncoding = response.headers().get("content-encoding");

assertEquals(OK.code(), response.statusCode(),
"Http status must be OK.");
assertEquals(contentEncoding, actualEncoding,
"Unexpected compressor selected.");
assertEquals(OK.code(), response.statusCode(),
"Http status must be OK.");
assertEquals(contentEncoding, actualEncoding,
"Unexpected compressor selected.");

final int receivedLength = parseInt(response.headers().get("content-length"));
final int expectedLength = parseInt(contentLength);
final int receivedLength = parseInt(response.headers().get("content-length"));
final int expectedLength = parseInt(contentLength);

if (contentEncoding == null) {
assertEquals(expectedLength, receivedLength,
"No compression was expected, so the content-length must match exactly.");
} else {
final int expectedLengthWithTolerance = expectedLength + (expectedLength / 100 * COMPRESSION_TOLERANCE_PERCENT);
assertTrue(receivedLength <= expectedLengthWithTolerance,
"Compression apparently failed: receivedLength: " + receivedLength +
" was supposed to be less or equal to expectedLength: " +
expectedLength + " plus " + COMPRESSION_TOLERANCE_PERCENT + "% tolerance, i.e. "
+ expectedLengthWithTolerance + ".");
if (contentEncoding == null) {
assertEquals(expectedLength, receivedLength,
"No compression was expected, so the content-length must match exactly.");
} else {
final int expectedLengthWithTolerance = expectedLength
+ (expectedLength / 100 * COMPRESSION_TOLERANCE_PERCENT);
assertTrue(receivedLength <= expectedLengthWithTolerance,
"Compression apparently failed: receivedLength: " + receivedLength +
" was supposed to be less or equal to expectedLength: " +
expectedLength + " plus " + COMPRESSION_TOLERANCE_PERCENT + "% tolerance, i.e. "
+ expectedLengthWithTolerance + ".");
}
assertEquals(TEXT, decompress(actualEncoding, response.body().getBytes()), "Unexpected body text.");
} catch (InterruptedException | ExecutionException e) {
fail(e);
}
assertEquals(TEXT, decompress(actualEncoding, response.body().getBytes()), "Unexpected body text.");
} catch (InterruptedException | ExecutionException e) {
fail(e);
} finally {
vertx.close();
}
}

public static void runDecompressorsTest(String endpoint, String acceptEncoding, String contentEncoding,
String method) {
LOG.infof("Endpoint %s; Accept-Encoding: %s; Content-Encoding: %s; Method: %s",
endpoint, acceptEncoding, contentEncoding, method);
final WebClient client = WebClient.create(Vertx.vertx(), new WebClientOptions()
.setLogActivity(true)
.setFollowRedirects(true)
.setDecompressionSupported(false));
final CompletableFuture<HttpResponse<Buffer>> future = new CompletableFuture<>();
client.postAbs(endpoint)
.putHeader(HttpHeaders.CONTENT_ENCODING.toString(), contentEncoding)
.putHeader(HttpHeaders.ACCEPT.toString(), "*/*")
.putHeader(HttpHeaders.USER_AGENT.toString(), "Tester")
.sendBuffer(compress(contentEncoding, TEXT), ar -> {
if (ar.succeeded()) {
future.complete(ar.result());
} else {
future.completeExceptionally(ar.cause());
}
});
Vertx vertx = Vertx.vertx();
try {
final HttpResponse<Buffer> response = future.get();
final String actualEncoding = response.headers().get("content-encoding");
final String body = decompress(actualEncoding, response.body().getBytes());
assertEquals(OK.code(), response.statusCode(), "Http status must be OK.");
assertEquals(TEXT, body, "Unexpected body text.");
} catch (InterruptedException | ExecutionException e) {
fail(e);
final WebClient client = WebClient.create(vertx, new WebClientOptions()
.setLogActivity(true)
.setFollowRedirects(true)
.setDecompressionSupported(false));
final CompletableFuture<HttpResponse<Buffer>> future = new CompletableFuture<>();
client.postAbs(endpoint)
.putHeader(HttpHeaders.CONTENT_ENCODING.toString(), contentEncoding)
.putHeader(HttpHeaders.ACCEPT.toString(), "*/*")
.putHeader(HttpHeaders.USER_AGENT.toString(), "Tester")
.sendBuffer(compress(contentEncoding, TEXT), ar -> {
if (ar.succeeded()) {
future.complete(ar.result());
} else {
future.completeExceptionally(ar.cause());
}
});
try {
final HttpResponse<Buffer> response = future.get();
final String actualEncoding = response.headers().get("content-encoding");
final String body = decompress(actualEncoding, response.body().getBytes());
assertEquals(OK.code(), response.statusCode(), "Http status must be OK.");
assertEquals(TEXT, body, "Unexpected body text.");
} catch (InterruptedException | ExecutionException e) {
fail(e);
}
} finally {
vertx.close();
}
}

Expand Down Expand Up @@ -178,18 +189,29 @@ public static String decompress(String algorithm, byte[] payload) {
if (algorithm != null && !"identity".equalsIgnoreCase(algorithm)) {
final EmbeddedChannel channel;
if ("gzip".equalsIgnoreCase(algorithm)) {
channel = new EmbeddedChannel(newZlibDecoder(ZlibWrapper.GZIP));
channel = new EmbeddedChannel(newZlibDecoder(ZlibWrapper.GZIP, 0));
} else if ("deflate".equalsIgnoreCase(algorithm)) {
channel = new EmbeddedChannel(newZlibDecoder(ZlibWrapper.ZLIB));
channel = new EmbeddedChannel(newZlibDecoder(ZlibWrapper.ZLIB, 0));
} else if ("br".equalsIgnoreCase(algorithm)) {
channel = new EmbeddedChannel(new BrotliDecoder());
} else {
throw new RuntimeException("Unexpected compression used by server: " + algorithm);
}

channel.writeInbound(Unpooled.copiedBuffer(payload));
channel.finish();
final ByteBuf decompressed = channel.readInbound();
return decompressed.readCharSequence(decompressed.readableBytes(), StandardCharsets.UTF_8).toString();

// Read all output buffers - decompression might produce multiple buffers
final StringBuilder result = new StringBuilder();
ByteBuf decompressed;
while ((decompressed = channel.readInbound()) != null) {
try {
result.append(decompressed.readCharSequence(decompressed.readableBytes(), StandardCharsets.UTF_8));
} finally {
decompressed.release();
}
}
return result.toString();
} else {
return new String(payload, StandardCharsets.UTF_8);
}
Expand Down
Loading