[NO ISSUE] Don't close Keep-Alive connections on non-200/401

Change-Id: Ia39f8f9030be5a738a71de4c336a98e326ee896f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2972
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java
index f02654e..a67b40e 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedResponse.java
@@ -79,9 +79,8 @@
         response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
         response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
         keepAlive = HttpUtil.isKeepAlive(request);
-        if (keepAlive) {
-            response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
-        }
+        response.headers().set(HttpHeaderNames.CONNECTION,
+                keepAlive ? HttpHeaderValues.KEEP_ALIVE : HttpHeaderValues.CLOSE);
     }
 
     @Override
@@ -119,17 +118,10 @@
                 }
                 future = ctx.channel().close();
             } else {
-                if (keepAlive && response.status() != HttpResponseStatus.UNAUTHORIZED) {
-                    response.headers().remove(HttpHeaderNames.CONNECTION);
-                }
-                // we didn't send anything to the user, we need to send an unchunked error response
+                // we didn't send anything to the user, we need to send an non-chunked error response
                 fullResponse(response.protocolVersion(), response.status(),
                         error == null ? ctx.alloc().buffer(0, 0) : error, response.headers());
             }
-            if (response.status() != HttpResponseStatus.UNAUTHORIZED) {
-                // since the request failed, we need to close the channel on complete
-                future.addListener(ChannelFutureListener.CLOSE);
-            }
         }
         done = true;
     }