Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
topframe committed Apr 6, 2024
1 parent 1e688b3 commit d7ee69d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/app/config/server/undertow/tow-server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</bean>
<bean class="com.aspectran.undertow.server.handler.encoding.ContentEncodingPredicates">
<properties>
<item name="contentSizeLargerThan" valueType="long">1024</item>
<item name="contentSizeLargerThan" valueType="long">32</item>
<item name="mediaTypes" type="array">
<value>text/xml</value>
<value>text/plain</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.aspectran.undertow.server.handler.encoding;

import com.aspectran.utils.annotation.jsr305.NonNull;
import com.aspectran.utils.logging.Logger;
import com.aspectran.utils.logging.LoggerFactory;
import com.aspectran.web.support.http.HttpHeaders;
import com.aspectran.web.support.http.MediaType;
import io.undertow.attribute.RequestHeaderAttribute;
Expand All @@ -33,6 +35,10 @@
*/
public class ContentEncodingPredicates {

private static final Logger logger = LoggerFactory.getLogger(ContentEncodingPredicates.class);

public static final long BREAK_EVEN_GZIP_SIZE = 23L;

private long contentSizeLargerThan = 0L;

private String[] mediaTypes;
Expand All @@ -55,6 +61,10 @@ public void setExcludedUserAgents(String[] excludedUserAgents) {
public Predicate createPredicate() {
List<Predicate> predicates = new ArrayList<>();
if (contentSizeLargerThan > 0L) {
if (contentSizeLargerThan < BREAK_EVEN_GZIP_SIZE) {
logger.warn("contentSizeLargerThan of " + contentSizeLargerThan +
" is inefficient for short content, break even is size " + BREAK_EVEN_GZIP_SIZE);
}
predicates.add(Predicates.requestLargerThan(contentSizeLargerThan));
}
if (mediaTypes != null && mediaTypes.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</bean>
<bean class="com.aspectran.undertow.server.handler.encoding.ContentEncodingPredicates">
<properties>
<item name="contentSizeLargerThan" valueType="long">1024</item>
<item name="contentSizeLargerThan" valueType="long">32</item>
<item name="mediaTypes" type="array">
<value>text/xml</value>
<value>text/plain</value>
Expand Down

0 comments on commit d7ee69d

Please sign in to comment.