zrhoffman commented on code in PR #4074: URL: https://github.com/apache/trafficcontrol/pull/4074#discussion_r1014488500
########## traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/http/BufferedResponseFilter.java: ########## @@ -0,0 +1,46 @@ +/* + * + * 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 org.apache.traffic_control.traffic_router.core.http; + +import com.google.common.net.HttpHeaders; +import org.apache.log4j.Logger; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class BufferedResponseFilter extends OncePerRequestFilter { + public static final Logger LOGGER = Logger.getLogger(BufferedResponseFilter.class); + + public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { + final BufferedResponse responseWrapper = new BufferedResponse(response); + + chain.doFilter(request, responseWrapper); + + // Close the connection without waiting for the 10-second connect timeout, + // in case the client does not close the connection. Even though this is + // the only case for which we are interested in sending Connection: close, + // sending it sometimes means we must always send it. From RFC 2616: + // > HTTP/1.1 applications that do not support persistent connections MUST + // > include the "close" connection option in every message. + response.addHeader(HttpHeaders.CONNECTION, "close"); Review Comment: > Looks like cloudfront.com is trying to close the connection but mistyped it as `Cneonction`: As @rob05c pointed out to me, `Cneonction` is just [a hack](https://stackoverflow.com/questions/4798461/cneonction-and-nncoection-http-headers) to get around Connection header differences between the origin and caches. > Maybe I don't fully understand the need for it here? Are `HEAD` requests broken without it? Nope we don't need it, it would only be to appease invalid requests like `curl -X HEAD`. But `curl -X HEAD` doesn't cause a timeout anyway in HTTP/2, so there isn't a long-term reason to do it, especially with the benefits from reusing the connection like you mentioned. Even if we did want to change any connection behavior, that belongs in a separate PR, #4074 should just be to resolve disparities between `HEAD` and `GET`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
