This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide workaround for Apache adding a "-gzip" to every outgoing etag #…
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
impl/src/main/java/org/dukecon/server/core/MyShallowEtagHeaderFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.dukecon.server.core; | ||
|
||
import org.springframework.web.filter.ShallowEtagHeaderFilter; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* The Apache web server we run in front of this application compresses the responses with gzip. It also modifies the etag. | ||
* This is a workaround to strip the additional etag from the header when the clients sends a request for this resource. | ||
* | ||
* @author Alexander Schwartz 2017 | ||
*/ | ||
public class MyShallowEtagHeaderFilter extends ShallowEtagHeaderFilter { | ||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) { | ||
@Override | ||
public String getHeader(String name) { | ||
String value = super.getHeader(name); | ||
if (name.equalsIgnoreCase("If-None-Match") && value != null) { | ||
value = value.replaceAll("-gzip", ""); | ||
} | ||
return value; | ||
} | ||
}; | ||
super.doFilterInternal(wrapper, response, filterChain); | ||
} | ||
} |