コード例 #1
0
        private static SocketIoRequestData CheckRequest(IDictionary<string, object> environment, IDictionary<string, string[]> headers)
        {
            var data = new SocketIoRequestData();

            var path = (string)environment["owin.RequestPath"];
            data.Path = path;

            var match = path.IndexOf("/socket.io", StringComparison.Ordinal) >= 0;

            var pieces = path.Split('/');

            environment["socketiodotnet.RequestPath"] = data.Path = path;

            if (path.IndexOf("/", StringComparison.Ordinal) == 0)
            {
                if (!match)
                {
                    int protocol = 0;
                    if (pieces.Length > 1)
                    {
                        int.TryParse(pieces[1], out protocol);

                        if (pieces.Length > 2)
                        {
                            environment["socketiodotnet.Transport"] = data.Transport = pieces[2];
                            if (pieces.Length > 3)
                                environment["socketiodotnet.Id"] = data.Id = pieces[3];
                        }
                    }

                    environment["socketiodotnet.RequestProtocol"] = data.RequestProtocol = protocol;
                }

                data.IsStatic = match;
            }

            return data;
        }
コード例 #2
0
        private async Task<ResultTuple> HandleHttpRequest(SocketIoRequestData data, IDictionary<string, object> environment, IDictionary<string, string[]> headers, Stream body)
        {
            ISocketIoTransport transport;
            if (!_config.TransportDictionary.TryGetValue(data.Transport, out transport))
                return await StringResultTuple("transport not supported", 500);

            try
            {
                return await transport.HandleRequest(data, environment, headers, body);
            }
            catch (Exception ex)
            {
                throw new NotImplementedException("not implemented", ex);
            }
        }
コード例 #3
0
 internal static Task<ResultTuple> StringResponseResult(SocketIoRequestData data, string str)
 {
     return StringResultTuple(
         string.Format("{0}:{1}:{2}:{3}",
                       data.RequestProtocol,
                       data.Config.GetHeartbeatStringValue(),
                       data.Config.GetCloseTimeoutStringValue(), 
                       str),
         200);
 }
コード例 #4
0
        private async Task<ResultTuple> HandleHandshake(SocketIoRequestData data, IDictionary<string, object> environment, IDictionary<string, string[]> headers, Stream body)
        {
            string error;
            bool authorized = await OnAuthorize(environment, headers, out error);

            if (!string.IsNullOrEmpty(error))
            {
                return await StringResultTuple(error, 500);
            }

            if (!authorized)
            {
                return await StringResultTuple("handshake unauthorized", 403);
            }

            var id = _config.IdGenerator(environment, headers);

            var hs = string.Join(":",
                id,
                _config.Heartbeats.HasValue ? _config.Heartbeats.Value.ToString(CultureInfo.InvariantCulture) : string.Empty,
                _config.CloseTimeout.HasValue ? _config.CloseTimeout.Value.ToString(CultureInfo.InvariantCulture) : string.Empty,
                _config.TransportsStringList);

            var jsonP = false;

            if (jsonP)
            {
                throw new NotImplementedException();
                return await StringResultTuple("todo", 200, "application/javascript");
            }
            else
            {
                return await StringResultTuple(hs, 200);
            }
        }