Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP fix response compression support #35804

Merged
merged 1 commit into from
Sep 8, 2023
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
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
Loading