All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.silentgo.core.action.GZipAction Maven / Gradle / Ivy

package com.silentgo.core.action;

import com.silentgo.core.action.annotation.Action;
import com.silentgo.core.action.gzip.GZIPResponseWrapper;
import com.silentgo.utils.log.Log;
import com.silentgo.utils.log.LogFactory;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

/**
 * Project : parent
 * Package : com.silentgo.core.action
 *
 * @author teddyzhu
 *         

* Created by teddyzhu on 2016/10/8. */ @Action public class GZipAction extends ActionChain { private static final Log LOGGER = LogFactory.get(); public static final String ACCEPT_ENCODING = "Accept-Encoding"; public static final String CONTENT_ENCODING = "Content-Encoding"; @Override public Integer priority() { return Integer.MIN_VALUE + 1; } @Override public void doAction(ActionParam param) throws Throwable { LOGGER.info("enter gzip action"); String ae = param.getRequest().getHeader(ACCEPT_ENCODING); //check if browser support gzip if (ae != null && ae.toLowerCase().contains("gzip")) { param.getResponse().addHeader("Vary", ACCEPT_ENCODING); GZIPResponseWrapper wrappedResponse = new GZIPResponseWrapper(param.getResponse()); param.setResponse(wrappedResponse); next(param); wrappedResponse.finish(); } else { next(param); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy