websocket origin headers
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1073 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
28102e6cea
commit
5ed8699b52
|
@ -53,6 +53,7 @@ public class SslHttpExchangeTest extends HttpExchangeTest
|
||||||
connector.setKeystore(keystore);
|
connector.setKeystore(keystore);
|
||||||
connector.setPassword("storepwd");
|
connector.setPassword("storepwd");
|
||||||
connector.setKeyPassword("keypwd");
|
connector.setKeyPassword("keypwd");
|
||||||
|
connector.setAllowRenegotiate(true);
|
||||||
|
|
||||||
_server.setConnectors(new Connector[]
|
_server.setConnectors(new Connector[]
|
||||||
{ connector });
|
{ connector });
|
||||||
|
|
|
@ -17,5 +17,6 @@ public interface WebSocket
|
||||||
void sendMessage(byte frame,byte[] data) throws IOException;
|
void sendMessage(byte frame,byte[] data) throws IOException;
|
||||||
void sendMessage(byte frame,byte[] data, int offset, int length) throws IOException;
|
void sendMessage(byte frame,byte[] data, int offset, int length) throws IOException;
|
||||||
void disconnect() throws IOException;
|
void disconnect() throws IOException;
|
||||||
|
boolean isOpen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,15 +64,38 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound
|
||||||
{
|
{
|
||||||
boolean more=true;
|
boolean more=true;
|
||||||
|
|
||||||
while (more)
|
try
|
||||||
{
|
{
|
||||||
int flushed=_generator.flush();
|
while (more)
|
||||||
int filled=_parser.parseNext();
|
{
|
||||||
|
int flushed=_generator.flush();
|
||||||
more = flushed>0 || filled>0 || !_parser.isBufferEmpty() || !_generator.isBufferEmpty();
|
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()
|
public boolean isIdle()
|
||||||
{
|
{
|
||||||
return _parser.isBufferEmpty() && _generator.isBufferEmpty();
|
return _parser.isBufferEmpty() && _generator.isBufferEmpty();
|
||||||
|
@ -116,5 +139,4 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound
|
||||||
{
|
{
|
||||||
_parser.fill(buffer);
|
_parser.fill(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,9 +64,10 @@ public abstract class WebSocketHandler extends HandlerWrapper
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
if ("WebSocket".equals(request.getHeader("Upgrade")) &&
|
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)
|
if (websocket!=null)
|
||||||
{
|
{
|
||||||
|
@ -76,6 +77,10 @@ public abstract class WebSocketHandler extends HandlerWrapper
|
||||||
|
|
||||||
response.setHeader("Upgrade","WebSocket");
|
response.setHeader("Upgrade","WebSocket");
|
||||||
response.addHeader("Connection","Upgrade");
|
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.sendError(101,"Web Socket Protocol Handshake");
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue