2

我有一个 Jersey-Application 代理对内部应用程序的请求,该应用程序应该无法直接访问。

@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标头集。到目前为止还可以。

现在,发送给客户端的响应还包含Content-Length标头集,大概是由 Jersey 自己在传出响应中设置的。当我在将标头发送到客户端之前检查标头时,所有标头都已正确设置,就像来自内部应用程序的响应一样。

Content-Length头会导致客户端无法正确解释响应,因为应该 设置Content-LengthTransfer-Encoding设置,如此所述。

Content-Length如果我已经设置了 Transfer-Encoding,如何防止 Jersey 设置标题?

4

0 回答 0