diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/SslHttpExchangeTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/SslHttpExchangeTest.java index 55c4397f954..1a76415cf45 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/SslHttpExchangeTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/SslHttpExchangeTest.java @@ -53,6 +53,7 @@ public class SslHttpExchangeTest extends HttpExchangeTest connector.setKeystore(keystore); connector.setPassword("storepwd"); connector.setKeyPassword("keypwd"); + connector.setAllowRenegotiate(true); _server.setConnectors(new Connector[] { connector }); diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java index c9c4ac9c688..eabeb74b8f9 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java @@ -17,5 +17,6 @@ public interface WebSocket void sendMessage(byte frame,byte[] data) throws IOException; void sendMessage(byte frame,byte[] data, int offset, int length) throws IOException; void disconnect() throws IOException; + boolean isOpen(); } } diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java index f19115533e0..0696b9edce0 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java @@ -64,15 +64,38 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound { boolean more=true; - while (more) + try { - int flushed=_generator.flush(); - int filled=_parser.parseNext(); - - more = flushed>0 || filled>0 || !_parser.isBufferEmpty() || !_generator.isBufferEmpty(); + while (more) + { + int flushed=_generator.flush(); + int filled=_parser.parseNext(); + + more = flushed>0 || filled>0 || !_parser.isBufferEmpty() || !_generator.isBufferEmpty(); + if (filled<0 || flushed<0) + _endp.close(); + + // System.err.println("flushed="+flushed+" filled="+filled+" more="+more+" endp="+_endp.isOpen()); + } + } + catch(IOException e) + { + System.err.println(e); + throw e; + } + finally + { + // TODO - not really the best way + if (!_endp.isOpen()) + _websocket.onDisconnect(); } } + public boolean isOpen() + { + return _endp!=null&&_endp.isOpen(); + } + public boolean isIdle() { return _parser.isBufferEmpty() && _generator.isBufferEmpty(); @@ -116,5 +139,4 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound { _parser.fill(buffer); } - } diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketHandler.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketHandler.java index 181d51ed885..77961b9adfe 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketHandler.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketHandler.java @@ -64,9 +64,10 @@ public abstract class WebSocketHandler extends HandlerWrapper public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("WebSocket".equals(request.getHeader("Upgrade")) && - "HTTP/1.1".equals(request.getProtocol())) + "HTTP/1.1".equals(request.getProtocol())) { - WebSocket websocket=doWebSocketConnect(request,request.getHeader("WebSocket-Protocol")); + String protocol=request.getHeader("WebSocket-Protocol"); + WebSocket websocket=doWebSocketConnect(request,protocol); if (websocket!=null) { @@ -76,6 +77,10 @@ public abstract class WebSocketHandler extends HandlerWrapper response.setHeader("Upgrade","WebSocket"); response.addHeader("Connection","Upgrade"); + response.addHeader("WebSocket-Origin",request.getScheme()+"://"+request.getServerName()); + response.addHeader("WebSocket-Location","ws://"+request.getHeader("Host")+request.getRequestURI()); + if (protocol!=null) + response.addHeader("WebSocket-Protocol",protocol); response.sendError(101,"Web Socket Protocol Handshake"); response.flushBuffer();