Java 泽西岛回应:don';t如果已设置传输编码,则设置内容长度标头
我有一个Jersey应用程序,它将请求代理给一个内部应用程序,该应用程序不应直接访问Java 泽西岛回应:don';t如果已设置传输编码,则设置内容长度标头,java,proxy,jersey-2.0,content-length,transfer-encoding,Java,Proxy,Jersey 2.0,Content Length,Transfer Encoding,我有一个Jersey应用程序,它将请求代理给一个内部应用程序,该应用程序不应直接访问 @GET @Path("/path") public static Response get( @Context UriInfo uriinfo, @Context HttpHeaders httpHeaders, byte[] body ) throws Exception{ //call the internal application Re
@GET
@Path("/path")
public static Response get(
@Context UriInfo uriinfo,
@Context HttpHeaders httpHeaders,
byte[] body
) throws Exception{
//call the internal application
Response response = get(url, uriinfo, httpHeaders, body, HttpMethod.GET);
ResponseBuilder rb = Response.
status(response.getStatusCode()).
entity(response.getResponseStream());
//set all headers from response
for(header : response.getResponseHeaders()){
rb.header(...);
}
Response r = rb.build();
//checking headers here, does NOT contain any Content-Length header
return r;
在来自内部应用程序的响应中,有Transfer Encoding=chunked
头集。到目前为止还可以
现在,发送到客户机的响应还包含内容长度
头集,可能是Jersey自己在传出响应上设置的。当我在将标题发送到客户端之前检查它们时,所有标题都被正确设置,就像来自内部应用程序的响应一样
Content Length
标题导致客户端无法正确解释响应,因为如上所述,应该设置Content Length
或Transfer Encoding
如果我已经设置了传输编码,如何防止Jersey设置
内容长度
标题?您好,请检查您是否解决了此问题?干杯,罗伯。@罗伯不是这样的,我本想这么做的。我的解决方法是在将响应发送到客户机之前删除传输编码
头,到目前为止,这对我是有效的。