我们可以为特定的URI启用Spring引导压缩吗



在我们的java springboot应用程序中,由于JSON结构庞大,我们需要压缩REST响应。浏览网页时发现,我们可以在application.properties中使用以下属性来启用压缩。

# Enable response compression
server.compression.enabled=true

# Minimum response where compression will kick in
server.compression.min-response-size=4096

# Mime types that should be compressed
server.compression.mime-types=text/html, text/xml, text/plain, text/css, text/javascript, application/javascript, application/json

它工作得很好,但它压缩了从该服务器返回的所有响应。

有没有办法过滤掉这种压缩。例如,我们只想压缩URI以compressmerge结尾的响应

或者是否有任何其他建议可以实现同样的目标。

谢谢

将自定义用户代理添加到要筛选的请求中,并在属性中的排除用户代理中进行配置。接下来,将该用户代理放入请求中。