001package co.codewizards.cloudstore.rest.shared; 002 003import java.util.List; 004 005import javax.ws.rs.container.ContainerRequestContext; 006import javax.ws.rs.core.MultivaluedMap; 007import javax.ws.rs.ext.ReaderInterceptorContext; 008import javax.ws.rs.ext.WriterInterceptorContext; 009 010public class GZIPUtil { 011 public static final String CLOUDSTORE_ENCODING_HEADER = "Cloudstore-Content-Encoding"; 012 public static final String CLOUDSTORE_ENCODING_HEADER_VALUE = "gzip"; 013 014 public static boolean isRequestCompressedWithGzip(ReaderInterceptorContext context){ 015 return CLOUDSTORE_ENCODING_HEADER_VALUE.equals( 016 context.getProperty(CLOUDSTORE_ENCODING_HEADER)); 017 } 018 019 public static boolean isRequestCompressedWithGzip(WriterInterceptorContext context){ 020 return CLOUDSTORE_ENCODING_HEADER_VALUE.equals( 021 context.getProperty(CLOUDSTORE_ENCODING_HEADER)); 022 } 023 024 public static boolean isRequestCompressedWithGzip(ContainerRequestContext requestContext){ 025 MultivaluedMap<String, String> headers = requestContext.getHeaders(); 026 List<String> encodingHeaderValues = headers.get(CLOUDSTORE_ENCODING_HEADER); 027 if(encodingHeaderValues == null || encodingHeaderValues.size() != 1){ 028 return false; 029 } 030 return CLOUDSTORE_ENCODING_HEADER_VALUE.equals(encodingHeaderValues.get(0)); 031 } 032}