From eb276dd59d53a0d5268c1fe33e9952b9a17f2bf8 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Wed, 6 Apr 2011 00:54:48 +0200 Subject: [PATCH] Another attempt to make server conform http. --- src/main/java/org/dynmap/web/HttpServerConnection.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/dynmap/web/HttpServerConnection.java b/src/main/java/org/dynmap/web/HttpServerConnection.java index c1c96d12..13d12533 100644 --- a/src/main/java/org/dynmap/web/HttpServerConnection.java +++ b/src/main/java/org/dynmap/web/HttpServerConnection.java @@ -166,7 +166,7 @@ public class HttpServerConnection extends Thread { } HttpResponse response = new HttpResponse(this, out); - + try { handler.handle(relativePath, request, response); } catch (IOException e) { @@ -186,9 +186,11 @@ public class HttpServerConnection extends Thread { //return; } - String connection = response.fields.get("Connection"); + boolean isKeepalive = !"close".equals(request.fields.get(HttpField.Connection)) && !"close".equals(response.fields.get(HttpField.Connection)); + String contentLength = response.fields.get("Content-Length"); - if (contentLength == null && connection == null) { + if (isKeepalive && contentLength == null) { + // A handler has been a bad boy, but we're here to fix it. response.fields.put("Content-Length", "0"); OutputStream responseBody = response.getBody(); @@ -201,7 +203,7 @@ public class HttpServerConnection extends Thread { } } - if (connection != null && connection.equals("close")) { + if (!isKeepalive) { out.flush(); socket.close(); return;