blob: 65578b9272b58ab5a9df2ccc843c308d3933caf0 [file] [log] [blame]
Jake Slack03928ae2014-05-13 18:41:56 -07001//
2// ========================================================================
3// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4// ------------------------------------------------------------------------
5// All rights reserved. This program and the accompanying materials
6// are made available under the terms of the Eclipse Public License v1.0
7// and Apache License v2.0 which accompanies this distribution.
8//
9// The Eclipse Public License is available at
10// http://www.eclipse.org/legal/epl-v10.html
11//
12// The Apache License v2.0 is available at
13// http://www.opensource.org/licenses/apache2.0.php
14//
15// You may elect to redistribute this code under either of these licenses.
16// ========================================================================
17//
18
19package org.eclipse.jetty.websocket;
20
21import java.io.IOException;
22import javax.servlet.http.HttpServletRequest;
23import javax.servlet.http.HttpServletResponse;
24
25import org.eclipse.jetty.io.EndPoint;
26
27public class WebSocketServletConnectionD06 extends WebSocketConnectionD06 implements WebSocketServletConnection
28{
29 private final WebSocketFactory factory;
30
31 public WebSocketServletConnectionD06(WebSocketFactory factory, WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol)
32 throws IOException
33 {
34 super(websocket,endpoint,buffers,timestamp,maxIdleTime,protocol);
35 this.factory = factory;
36 }
37
38 /* ------------------------------------------------------------ */
39 public void handshake(HttpServletRequest request, HttpServletResponse response, String subprotocol) throws IOException
40 {
41 String key = request.getHeader("Sec-WebSocket-Key");
42
43 response.setHeader("Upgrade","WebSocket");
44 response.addHeader("Connection","Upgrade");
45 response.addHeader("Sec-WebSocket-Accept",hashKey(key));
46 if (subprotocol!=null)
47 {
48 response.addHeader("Sec-WebSocket-Protocol",subprotocol);
49 }
50
51 response.sendError(101);
52
53 onFrameHandshake();
54 onWebSocketOpen();
55 }
56
57 @Override
58 public void onClose()
59 {
60 super.onClose();
61 factory.removeConnection(this);
62 }
63}