0

I have Jersey rest services running on tomcat. I'm returning a Response object for a rest call, but the entity of the payload is a list of objects of a class that i defined. How can i set the content-length in the response header for this List

    @Path("/somePath")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response myRestAPI(@CookieParam(value = "value") String cookieValue) {
        /*..
        * some business logic here
        */
        List<MyObject> myObjects = getMyObjectList();
        return Response.ok(myObjects).cookie(createCookie(value)).build();
    }

I intend on setting the content-length header in the Response object as

return Response.ok(myObjects).header("content-length", length).cookie(createCookie(value)).build();

How can i find the length of the list? Thanks in advance

Some guy
  • 1,210
  • 1
  • 17
  • 39

1 Answers1

0

I guess the Content-Length header should be automatically included. In my case using RestEasy (not Jersey) it is.

Can you confirm that the header is not included, e.g. using curl or Firebug?

Finally, just to be 100% sure: Content-Length is the length of the HTTP content (the body, see here), not the size of the list, as returned by List.size().

Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90
  • I have checked it, the content-length is not set. Right now, `Transder-Encoding : chunked` is set and on investigating i found that it is the default header set and to remove that I need to set the `content-length` header – Some guy Sep 10 '13 at 09:26
  • I see... I found [this](https://jersey.java.net/apidocs/2.2/jersey/org/glassfish/jersey/server/ServerProperties.html#OUTBOUND_CONTENT_LENGTH_BUFFER). Could it be that the response is too big, thus you either have to live with the chunked transfer or increase the length of the buffer. – Nikos Paraskevopoulos Sep 10 '13 at 09:35