001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.web.server; 018 019import org.springframework.util.unit.DataSize; 020 021/** 022 * Simple server-independent abstraction for compression configuration. 023 * 024 * @author Ivan Sopov 025 * @author Andy Wilkinson 026 * @author Stephane Nicoll 027 * @since 2.0.0 028 */ 029public class Compression { 030 031 private boolean enabled = false; 032 033 private String[] mimeTypes = new String[] { "text/html", "text/xml", "text/plain", 034 "text/css", "text/javascript", "application/javascript", "application/json", 035 "application/xml" }; 036 037 private String[] excludedUserAgents = null; 038 039 private DataSize minResponseSize = DataSize.ofKilobytes(2); 040 041 /** 042 * Return whether response compression is enabled. 043 * @return {@code true} if response compression is enabled 044 */ 045 public boolean getEnabled() { 046 return this.enabled; 047 } 048 049 public void setEnabled(boolean enabled) { 050 this.enabled = enabled; 051 } 052 053 /** 054 * Return the MIME types that should be compressed. 055 * @return the MIME types that should be compressed 056 */ 057 public String[] getMimeTypes() { 058 return this.mimeTypes; 059 } 060 061 public void setMimeTypes(String[] mimeTypes) { 062 this.mimeTypes = mimeTypes; 063 } 064 065 public String[] getExcludedUserAgents() { 066 return this.excludedUserAgents; 067 } 068 069 public void setExcludedUserAgents(String[] excludedUserAgents) { 070 this.excludedUserAgents = excludedUserAgents; 071 } 072 073 /** 074 * Return the minimum "Content-Length" value that is required for compression to be 075 * performed. 076 * @return the minimum content size in bytes that is required for compression 077 */ 078 public DataSize getMinResponseSize() { 079 return this.minResponseSize; 080 } 081 082 public void setMinResponseSize(DataSize minSize) { 083 this.minResponseSize = minSize; 084 } 085 086}