Example #1
0
        private void Processing(IChannel channel, Request request)
        {
            //웹소켓 요청인가?
            if (request.GetHeader("connection") == "Upgrade")
            {
                if (request.GetHeader("upgrade") == "websocket")
                    UpgradeWebSocket(channel, request);
                return;
            }

            //JSON
            if (request.GetHeader("Accept") != null && request.GetHeader("Accept").IndexOf("application/json") >= 0)
            {
                UriFinder finder = GetJSONUriFinder(request);
                if (finder != null)
                {
                    var response = new Response();
                    response.SetContent(finder.GetHandler(request.GetPath()).ToString());
                    response.ContentType = "application/json";
                    response.Protocol = request.GetProtocol();
                    channel.SendMessage(response);
                    return;
                }
            }

            //여기서 여러가지 예외 처리를!
            IUriHandler handler = GetUriHandler(channel, request);
            if (handler != null)
            {
                handler.Handle(channel, request);
            }
            else
            {
                var response = new Response();
                response.Status = 401;
                response.Protocol = request.GetProtocol();
                channel.SendMessage(response);
            }
        }
Example #2
0
        private void UpgradeWebSocket(IChannel channel, Request request)
        {
            var response = new Response { Status = 101, Protocol="1.1"};

            var protocol = channel as IKeepProtocolChannel;
            if (protocol == null)
                return;

            var finder = GetWebSocketUriFinder(request);
            if (finder == null)
                return;

            var handler = channel as IKeepHandlerChannel;
            if (handler == null)
                return;

            handler.SetHandler((IChannelHandler)finder.GetHandler(request.GetPath()));
            response.GetHeader().AppendLine("Upgrade: websocket")
                .AppendLine("Connection: Upgrade")
                .AppendLine("Sec-WebSocket-Accept: " + GetWebSocketAcceptCode(request.GetHeader("Sec-WebSocket-Key")));
            channel.SendMessage(response);
            protocol.SetProtocol(WebSocketProtocol.Protocol);
            handler.GetHandler().Connected(channel);
        }
Example #3
0
        private void UpgradeWebSocket(IChannel channel, Request request)
        {
            var response = new Response { Status = 101, Protocol="1.1"};

            var finder = GetWebSocketUriFinder(request);
            if (finder == null)
                return;

            channel.SetConfig("handler", finder.GetHandler(request.GetPath()));
            //((IChannelHandler)channel.GetConfig("handler")).GetHandler();
            response.GetHeader().AppendLine("Upgrade: websocket")
                .AppendLine("Connection: Upgrade")
                .AppendLine("Sec-WebSocket-Accept: " + GetWebSocketAcceptCode(request.GetHeader("Sec-WebSocket-Key")));
            channel.SendMessage(response);
            channel.SetConfig("encoder", Protocol.PacketEncoder.WebSocket.WebSocketEncoder.Encoder);
            channel.SetConfig("decoder", Protocol.PacketEncoder.WebSocket.WebSocketDecoder.Decoder);
            //protocol.SetProtocol(WebSocketProtocol.Protocol);
            ((IChannelHandler)channel.GetConfig("handler")).Connected(null/**/);
            //handler.GetHandler().Connected(channel);
        }