From 3ea5c29ea633e1081ff1f7dc73e71737bce18523 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 1 Aug 2016 10:06:22 -0700 Subject: [PATCH] Fixes #749 - Invalid WebSocket Upgrade should result in error 400, not 405 --- .../websocket/servlet/ServletUpgradeResponse.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java index 4b6914fd415..9ead4c16c0e 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java @@ -81,8 +81,9 @@ public class ServletUpgradeResponse extends UpgradeResponse public void sendError(int statusCode, String message) throws IOException { setSuccess(false); - commitHeaders(); + applyHeaders(); response.sendError(statusCode, message); + response.flushBuffer(); // commit response response = null; } @@ -90,8 +91,9 @@ public class ServletUpgradeResponse extends UpgradeResponse public void sendForbidden(String message) throws IOException { setSuccess(false); - commitHeaders(); + applyHeaders(); response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + response.flushBuffer(); // commit response response = null; } @@ -111,11 +113,11 @@ public class ServletUpgradeResponse extends UpgradeResponse public void complete() { - commitHeaders(); + applyHeaders(); response = null; } - private void commitHeaders() + private void applyHeaders() { // Transfer all headers to the real HTTP response for (Map.Entry> entry : getHeaders().entrySet())