Skip to content

Cache Control Plugin

tfredrich edited this page Sep 17, 2012 · 5 revisions
public class LastModifiedHeaderPostprocessor
implements Postprocessor
{
DateAdapter fmt = new HttpHeaderTimestampAdapter();

@Override
public void process(Request request, Response response)
{
	if (!request.isMethodGet()) return;
	if (!response.hasBody()) return;

	Object body = response.getBody();

	if (!response.hasHeader(LAST_MODIFIED) && Timestamped.class.isAssignableFrom(body.getClass()))
	{
		response.addHeader(LAST_MODIFIED, fmt.format(((Timestamped) body).getUpdatedAt()));
	}
}
}

Clone this wiki locally