com.jetdrone.vertx.yoke.middleware.Compress Maven / Gradle / Ivy
/**
* Copyright 2011-2014 the original author or authors.
*/
package com.jetdrone.vertx.yoke.middleware;
import com.jetdrone.vertx.yoke.Middleware;
import com.jetdrone.vertx.yoke.middleware.filters.DeflateWriterFilter;
import com.jetdrone.vertx.yoke.middleware.filters.GZipWriterFilter;
import org.jetbrains.annotations.NotNull;
import org.vertx.java.core.Handler;
import java.io.IOException;
import java.util.regex.Pattern;
/**
* # Compress
*
* Middleware to compress responses and set the appropriate response headers.
* Not all responses are compressed, the middleware first inspects if the
* request accepts compression and tries to select the best matched algorithm.
*
* You can specify which content types are compressable and by default json/text/javascript
* are enabled.
*/
public class Compress extends Middleware {
/**
* Regular expression to identify resources that are subject to compression
*/
private final Pattern filter;
/**
* Creates a new Compression Middleware given a regular expression of allowed mime types
*
* @param filter Regular expression to specify which mime types are allowed to be compressed
*/
public Compress(@NotNull final Pattern filter) {
this.filter = filter;
}
/**
* Creates a new Compression Middleware using the default allowed mime types
*/
public Compress() {
this(Pattern.compile("json|text|javascript"));
}
@Override
public void handle(@NotNull final YokeRequest request, @NotNull final Handler