2.12.4.2. 服务器端 GZIP 配置
您可以通过在类路径上的 javax.ws.rs.ext.Providers
文件中包含它们的类名称来启用拦截器。已定义文件的上限使用 Web 应用上下文参数 resteasy.gzip.max.input
进行设置。如果在服务器端超过这个限制,GZIPDecodingInterceptor
将返回一个带有状态为 413 的响应 - Request Entity Too Large
以及指定上限的消息。
2.12.4.2.1. 客户端 GZIP 配置
您可以通过将 GZIP 拦截器注册到 客户端
或 WebTarget
来启用 GZIP 拦截器。例如:
Client client = new ResteasyClientBuilder() // Activate gzip compression on client: .register(AcceptEncodingGZIPFilter.class) .register(GZIPDecodingInterceptor.class) .register(GZIPEncodingInterceptor.class) .build();
您可以通过创建具有特定值的 GZIPDecodingInterceptor
实例来配置定义文件的上限:
Client client = new ResteasyClientBuilder() // Activate gzip compression on client: .register(AcceptEncodingGZIPFilter.class) .register(new GZIPDecodingInterceptor(256)) .register(GZIPEncodingInterceptor.class) .build();
如果在客户端上超过了上限,GZIPDecodingInterceptor 将
引发 ProcessingException
,并显示指定上限的消息。