You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/11/23 17:36:33 UTC

[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #4074: Set Content-Length header in Traffic Router

rawlinp commented on a change in pull request #4074:
URL: https://github.com/apache/trafficcontrol/pull/4074#discussion_r755366224



##########
File path: 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:
       This worries me, because we might be fixing the performance of _invalid_ requests (e.g. `curl -X HEAD`), at the expense of _valid_ requests. Keeping client connections alive where possible can be a good thing.




-- 
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: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org