package io.corbel.lib.ws.filter;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.HttpHeaders;

public class ETagResponseFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

        String rawEtag = responseContext.getHeaderString(HttpHeaders.ETAG);
        String requestedEtag = requestContext.getHeaderString(HttpHeaders.IF_NONE_MATCH);

        if (rawEtag != null && rawEtag.equals(requestedEtag)) {
            responseContext.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            responseContext.setEntity(null);
        }

    }

}

@@ -27,16 +27,42 @@
 ilter;%0A%0A
+import java.io.Closeable;%0A
 import j
@@ -848,16 +848,166 @@
 IFIED);%0A
+            if (responseContext.getEntity() instanceof Closeable) %7B%0A                ((Closeable) responseContext.getEntity()).close();%0A            %7D;%0A
         

fix etag filter, closing entity response when is necessary