How to setHeader in ResourceStreamRequestHandler#configure(..) (migration issue)

419 views Asked by At

I'm migrating wicket 1.4 to 6 through 1.5. I encounter an issue that I cannot fix. In wicket 1.4 I used to have (note: Yes, I do have detach)

public class TempFileResourceRequestTarget extends ResourceStreamRequestTarget implements Serializable {
    @Override
    protected void configure(final RequestCycle requestCycle, final Response response, 
            final IResourceStream resourceStream) {
        super.configure(requestCycle, response, resourceStream);
        ((WebResponse)response).getHttpServletResponse().setHeader("Cache-Control","");
        ((WebResponse)response).getHttpServletResponse().setHeader("Pragma","");
}

In wicket 1.5/6 I changed it into this:

public class TempFileResourceRequestTarget extends ResourceStreamRequestHandler implements Serializable {
    @Override
    protected void configure(ResourceStreamResource resource) {
        super.configure(resource);
        ((HttpServletResponse)resource).setHeader("Cache-Control","");
        ((HttpServletResponse)resource).setHeader("Pragma","");
    }
}

I was desperate and was trying to find anything that does include setHeader() - I do believe I found it in migration guide or something similar. Anyway this does not work. How do I set it? in renderHead? No clue. Thanks in advance.

1

There are 1 answers

1
martin-g On BEST ANSWER

ResourceStreamResource doesn't implement HttpServletResponse. You could use ResourceStreamResource#setCacheDuration(Duration.NONE) to disable caching.

It will do the following for you:

 public void disableCaching() {
    this.setDateHeader("Date", Time.now());
    this.setDateHeader("Expires", Time.START_OF_UNIX_TIME);
    this.setHeader("Pragma", "no-cache");
    this.setHeader("Cache-Control", "no-cache, no-store");
 }

Is this what you are after?