zrhoffman commented on code in PR #4074:
URL: https://github.com/apache/trafficcontrol/pull/4074#discussion_r1011972764


##########
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:
   It can be, but some CDNs seem to prefer `Connection: close` for redirects:
   
   *   ```shell
       [zrhoffman@computer ~]$ curl -I https://apple.com/
       HTTP/1.1 301 Redirect
       Date: Wed, 02 Nov 2022 15:18:11 GMT
       Connection: close
       Via: http/1.1 xxxx.ts.apple.com (acdn/000.00000)
       Cache-Control: no-store
       Location: https://www.apple.com/
       Content-Type: text/html
       Content-Language: en
       X-Cache: none
       CDNUUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxxxxxxxx
       Content-Length: 304
       ```
   
   *   ```shell
       [zrhoffman@computer ~]$ curl -I http://fastly.com/
       HTTP/1.1 301 Moved Permanently
       Connection: close
       Content-Length: 0
       Retry-After: 0
       Accept-Ranges: bytes
       Date: Wed, 02 Nov 2022 15:18:50 GMT
       X-Served-By: cache-xxx0000-XXX
       X-Cache: HIT
       X-Cache-Hits: 0
       Cache-Control: max-age=0, private, must-revalidate
       Server: Artisanal bits
       Location: https://fastly.com/
       ```
   
   *   Looks like cloudfront.com is trying to close the connection but mistyped 
it as `Cneonction`:
     ```shell
       [zrhoffman@computer ~]$ curl -I http://cloudfront.com/
       HTTP/1.1 302 Found
       Date: Wed, 02 Nov 2022 15:19:19 GMT
       Server: Server
       Location: http://aws.amazon.com/cloudfront
       Cneonction: close
       Content-Type: text/html; charset=iso-8859-1
       ```



-- 
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]

Reply via email to