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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 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 Logger LOGGER = LoggerFactory.getLogger(GZipAction.class);
@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.contains("gzip")) {
GZIPResponseWrapper wrappedResponse = new GZIPResponseWrapper(param.getResponse());
param.setResponse(wrappedResponse);
nextAction.doAction(param);
wrappedResponse.finishResponse();
} else {
nextAction.doAction(param);
}
}
}