Example usage for org.springframework.boot.web.server Compression setMimeTypes

List of usage examples for org.springframework.boot.web.server Compression setMimeTypes

Introduction

In this page you can find the example usage for org.springframework.boot.web.server Compression setMimeTypes.

Prototype

public void setMimeTypes(String[] mimeTypes) 

Source Link

Usage

From source file:org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests.java

private String setUpFactoryForCompression(int contentSize, String[] mimeTypes, String[] excludedUserAgents)
        throws Exception {
    char[] chars = new char[contentSize];
    Arrays.fill(chars, 'F');
    String testContent = new String(chars);
    AbstractServletWebServerFactory factory = getFactory();
    Compression compression = new Compression();
    compression.setEnabled(true);//  w w w. j  a  v  a2 s. c o  m
    if (mimeTypes != null) {
        compression.setMimeTypes(mimeTypes);
    }
    if (excludedUserAgents != null) {
        compression.setExcludedUserAgents(excludedUserAgents);
    }
    factory.setCompression(compression);
    factory.addInitializers(new ServletRegistrationBean<HttpServlet>(new HttpServlet() {

        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            resp.setContentType("text/plain");
            resp.setContentLength(testContent.length());
            resp.getWriter().write(testContent);
            resp.getWriter().flush();
        }

    }, "/test.txt"));
    this.webServer = factory.getWebServer();
    this.webServer.start();
    return testContent;
}