Skip to content

Commit

Permalink
Re-add check that client supports gzip
Browse files Browse the repository at this point in the history
I forgot to re-add the check to make sure the client supports gzip
compression
  • Loading branch information
EdwardRaff committed Feb 6, 2015
1 parent f625bc3 commit fb1f1d4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/spark/webserver/MatcherFilter.java
Expand Up @@ -17,6 +17,7 @@
package spark.webserver;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -239,8 +240,10 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
if (httpResponse.getContentType() == null) {
httpResponse.setContentType("text/html; charset=utf-8");
}
boolean acceptsGzip = Collections.list(httpRequest.getHeaders("Accept-Encoding")).stream().anyMatch(s -> s.contains("gzip"));

//gzip compression support
if(httpResponse.getHeaders("Content-Encoding").contains("gzip"))
if(acceptsGzip && httpResponse.getHeaders("Content-Encoding").contains("gzip"))
{
try(GZIPOutputStream gzipOut = new GZIPOutputStream(httpResponse.getOutputStream()))
{
Expand Down

0 comments on commit fb1f1d4

Please sign in to comment.