-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(etag): remove etag filter (#1141)
* fix(etag): remove etag filter Add a content caching filter instead of the `ETag` filter so that we: a) don't have to waste CPU cycles computing MD5 hashes b) but still set `Content-Length` on the response to avoid chunked transfers * fixup! fix(etag): remove etag filter Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
97c6e22
commit d064672
Showing
2 changed files
with
55 additions
and
8 deletions.
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
51 changes: 51 additions & 0 deletions
51
gate-web/src/main/groovy/com/netflix/spinnaker/gate/filters/ContentCachingFilter.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,51 @@ | ||
/* | ||
* Copyright 2020 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.filters; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletResponse; | ||
import org.springframework.web.util.ContentCachingResponseWrapper; | ||
|
||
/** | ||
* This filter simply buffers/caches the response so that the Content-Length header can be set. | ||
* Setting the Content-Length header prevents a response from being transferred with chunked | ||
* encoding which may be problematic for some http clients. | ||
*/ | ||
public class ContentCachingFilter implements Filter { | ||
@Override | ||
public void init(FilterConfig filterConfig) {} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
|
||
ContentCachingResponseWrapper responseWrapper = | ||
new ContentCachingResponseWrapper((HttpServletResponse) response); | ||
|
||
chain.doFilter(request, responseWrapper); | ||
responseWrapper.copyBodyToResponse(); | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
} |