如何在 Quarkus 中通过 https 处理压缩静态资源
How to handle compression static resources over https in Quarkus
问题
我想在Quarkus中压缩js、css、图片等静态资源。我是压缩启动配置quarkus.http.enable-compression:true。它在 HTTP 模式下运行良好,但在 https.
上运行不正常
预期行为
内容将通过 HTTPS 压缩为 GZIP
实际行为
没有基于 HTTPS 的 GZIP 压缩
重现
重现该行为的步骤:
- Git pull from quarkus-demo 我之前做的
- 使用 mkcert
创建证书以在本地主机中启用 SSL
- 使用命令
mvn clean package -Dquarkus.profile=prod
为 运行 编译 HTTPS。如果您想通过 HTTP 进行测试,请使用此命令 运行 mvn quarkus:dev
- 运行 使用此命令的 quarkus 应用
java -jar target\quarkus-app\quarkus-run.jar
- 最后,打开浏览器访问
https://localhost
或http://localhost:8080
,然后请在网络选项卡[=74=中检查元素以检查加载的资源详细信息]
application.yml
quarkus:
application:
version: 1.0.0-SNAPSHOT
http:
port: 8080
enable-compression: true
申请-prod.yml
quarkus:
http:
port: 8080
ssl-port: 443
ssl:
certificate:
file: D:\system\server\localhost.pem
key-file: D:\system\server\localhost-key.pem
insecure-requests: redirect
enable-compression: true
HTTP
Request URL: http://localhost:8080/js/chunk-vendors.e96189d0.js
Request Method: GET
Status Code: 200 OK
Remote Address: 127.0.0.1:8080
Referrer Policy: strict-origin-when-cross-origin
accept-ranges: bytes
content-encoding: gzip
content-type: text/javascript;charset=UTF-8
date: Thu, 10 Mar 2022 07:41:46 GMT
transfer-encoding: chunked
HTTPS
Request URL: https://localhost/js/chunk-vendors.e96189d0.js
Request Method: GET
Status Code: 200
Remote Address: [::1]:443
Referrer Policy: strict-origin-when-cross-origin
accept-ranges: bytes
cache-control: public, immutable, max-age=86400
content-length: 880682
content-type: text/javascript;charset=UTF-8
date: Thu, 10 Mar 2022 07:45:07 GMT
last-modified: Thu, 10 Mar 2022 07:45:07 GMT
vary: accept-encoding
仅供参考:我试过使用 vert.x 过滤器但没有帮助 :(
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class FilterRegistrator {
void setUpFilter(@Observes Filters filters) {
filters.register((rc) -> {
rc.next();
if (rc.normalizedPath().matches("^.*\.(js|css|svg|png)$")) {
rc.response().headers().add("content-encoding", "gzip");
}
}, 0);
}
}
此问题已于 Quarkus 2.7.5.Final
解决
问题
我想在Quarkus中压缩js、css、图片等静态资源。我是压缩启动配置quarkus.http.enable-compression:true。它在 HTTP 模式下运行良好,但在 https.
上运行不正常预期行为
内容将通过 HTTPS 压缩为 GZIP
实际行为
没有基于 HTTPS 的 GZIP 压缩
重现
重现该行为的步骤:
- Git pull from quarkus-demo 我之前做的
- 使用 mkcert 创建证书以在本地主机中启用 SSL
- 使用命令
mvn clean package -Dquarkus.profile=prod
为 运行 编译 HTTPS。如果您想通过 HTTP 进行测试,请使用此命令 运行mvn quarkus:dev
- 运行 使用此命令的 quarkus 应用
java -jar target\quarkus-app\quarkus-run.jar
- 最后,打开浏览器访问
https://localhost
或http://localhost:8080
,然后请在网络选项卡[=74=中检查元素以检查加载的资源详细信息]
application.yml
quarkus:
application:
version: 1.0.0-SNAPSHOT
http:
port: 8080
enable-compression: true
申请-prod.yml
quarkus:
http:
port: 8080
ssl-port: 443
ssl:
certificate:
file: D:\system\server\localhost.pem
key-file: D:\system\server\localhost-key.pem
insecure-requests: redirect
enable-compression: true
HTTP
Request URL: http://localhost:8080/js/chunk-vendors.e96189d0.js
Request Method: GET
Status Code: 200 OK
Remote Address: 127.0.0.1:8080
Referrer Policy: strict-origin-when-cross-origin
accept-ranges: bytes
content-encoding: gzip
content-type: text/javascript;charset=UTF-8
date: Thu, 10 Mar 2022 07:41:46 GMT
transfer-encoding: chunked
HTTPS
Request URL: https://localhost/js/chunk-vendors.e96189d0.js
Request Method: GET
Status Code: 200
Remote Address: [::1]:443
Referrer Policy: strict-origin-when-cross-origin
accept-ranges: bytes
cache-control: public, immutable, max-age=86400
content-length: 880682
content-type: text/javascript;charset=UTF-8
date: Thu, 10 Mar 2022 07:45:07 GMT
last-modified: Thu, 10 Mar 2022 07:45:07 GMT
vary: accept-encoding
仅供参考:我试过使用 vert.x 过滤器但没有帮助 :(
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
@ApplicationScoped
public class FilterRegistrator {
void setUpFilter(@Observes Filters filters) {
filters.register((rc) -> {
rc.next();
if (rc.normalizedPath().matches("^.*\.(js|css|svg|png)$")) {
rc.response().headers().add("content-encoding", "gzip");
}
}, 0);
}
}
此问题已于 Quarkus 2.7.5.Final
解决