Skip to content

Commit

Permalink
Merge pull request #35804 from mkouba/fix-http-compression
Browse files Browse the repository at this point in the history
HTTP fix response compression support
  • Loading branch information
mkouba authored Sep 8, 2023
2 parents bc9e7ef + 2fb9216 commit fad4344
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Set;

import io.quarkus.vertx.http.runtime.HttpCompression;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpHeaders;
Expand All @@ -24,33 +23,31 @@ public HttpCompressionHandler(Handler<RoutingContext> routeHandler, HttpCompress

@Override
public void handle(RoutingContext context) {
context.addEndHandler(new Handler<AsyncResult<Void>>() {
context.addHeadersEndHandler(new Handler<Void>() {
@Override
public void handle(AsyncResult<Void> result) {
if (result.succeeded()) {
MultiMap headers = context.response().headers();
String contentEncoding = headers.get(HttpHeaders.CONTENT_ENCODING);
if (contentEncoding != null && HttpHeaders.IDENTITY.toString().equals(contentEncoding)) {
switch (compression) {
case ON:
headers.remove(HttpHeaders.CONTENT_ENCODING);
break;
case UNDEFINED:
String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
if (contentType != null) {
int paramIndex = contentType.indexOf(';');
if (paramIndex > -1) {
contentType = contentType.substring(0, paramIndex);
}
if (compressedMediaTypes.contains(contentType)) {
headers.remove(HttpHeaders.CONTENT_ENCODING);
}
public void handle(Void result) {
MultiMap headers = context.response().headers();
String contentEncoding = headers.get(HttpHeaders.CONTENT_ENCODING);
if (contentEncoding != null && HttpHeaders.IDENTITY.toString().equals(contentEncoding)) {
switch (compression) {
case ON:
headers.remove(HttpHeaders.CONTENT_ENCODING);
break;
case UNDEFINED:
String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
if (contentType != null) {
int paramIndex = contentType.indexOf(';');
if (paramIndex > -1) {
contentType = contentType.substring(0, paramIndex);
}
break;
default:
// OFF - no action is needed because the "Content-Encoding: identity" header is set
break;
}
if (compressedMediaTypes.contains(contentType)) {
headers.remove(HttpHeaders.CONTENT_ENCODING);
}
}
break;
default:
// OFF - no action is needed because the "Content-Encoding: identity" header is set
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Set;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpHeaders;
Expand All @@ -25,12 +24,10 @@ public HttpCompressionHandler(Handler<RoutingContext> routeHandler, Set<String>

@Override
public void handle(RoutingContext context) {
context.addEndHandler(new Handler<AsyncResult<Void>>() {
context.addHeadersEndHandler(new Handler<Void>() {
@Override
public void handle(AsyncResult<Void> result) {
if (result.succeeded()) {
compressIfNeeded(context, compressedMediaTypes);
}
public void handle(Void result) {
compressIfNeeded(context, compressedMediaTypes);
}
});
routeHandler.handle(context);
Expand Down

0 comments on commit fad4344

Please sign in to comment.