Jersey expires, title does not work

I use set 1.11 to pass some RESTful web services.

Every time I browse the REST resource using Chrome, I notice that the HTTP Header Expires is set to Thu, 01 Jan 1970 01:00:00 CET .

I tried changing the response add:

return Response.ok( myObject ).expires(new Date(System.currentTimeMillis() + 3000)).build(); 

Unfortunately, this adds another Expires HTTP header instead of replacing the old one.

What is the problem?

+4
source share
4 answers

FWIW, I see the same behavior. The container here is JBoss 4.2.3. This is a PUT method with BASIC authentication. My answer is created this way:

 Date exp = new Date(System.currentTimeMillis() + lifetime); return Response.noContent().expires(exp).build(); 

When cURL is called, these are the returned headers:

 < HTTP/1.1 204 No Content < Server: Apache-Coyote/1.1 < Pragma: No-cache < Cache-Control: no-cache < Expires: Thu, 01 Jan 1970 01:00:00 CET < X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (... < Expires: Tue, 13 Mar 2012 11:08:54 GMT < Date: Tue, 13 Mar 2012 11:08:24 GMT < 
+1
source

This means that your browser does not cache the requested resource. The date itself is a timestamp with zero seconds, the beginning of the UNIX era.

0
source

I found that my application server (in this case, JBoss 4.2.3.GA) would not allow Jersey to rewrite the title this way.

To workaround:

  • Insert the response object into the method using the parameter:

    @Context javax.servlet.http.HttpServletResponse response

  • Set the title for the response object, and do not use .expires ():

    response.setDateHeader (Expires, System.currentTimeMillis () + 14400000);

I used # 2 before I called .build () in ResponseBuilder, not sure if it matters or not when you do it.

0
source

I have the same problem. My workaround:

  • Insert @Context javax.servlet.http.HttpServletResponse response

  • Reset response object response.reset();

  • Use ResponseBuilder to set headers. return Response .ok(icon.getData()) .type(icon.getContentType()) .expires(cal.getTime()) .build();

0
source

Source: https://habr.com/ru/post/1394864/


All Articles