private Task ProcessNegotiationRequest(HostContext context) { // Total amount of time without a keep alive before the client should attempt to reconnect in seconds. var keepAliveTimeout = _configurationManager.KeepAliveTimeout(); string connectionId = Guid.NewGuid().ToString("d"); string connectionToken = connectionId + ':' + GetUserIdentity(context); var payload = new { Url = context.Request.LocalPath.Replace("/negotiate", ""), ConnectionToken = ProtectedData.Protect(connectionToken, Purposes.ConnectionToken), ConnectionId = connectionId, KeepAliveTimeout = keepAliveTimeout != null ? keepAliveTimeout.Value.TotalSeconds : (double?)null, DisconnectTimeout = _configurationManager.DisconnectTimeout.TotalSeconds, TryWebSockets = _transportManager.SupportsTransport(WebSocketsTransportName) && context.Environment.SupportsWebSockets(), ProtocolVersion = _protocolResolver.Resolve(context.Request).ToString(), TransportConnectTimeout = _configurationManager.TransportConnectTimeout.TotalSeconds }; if (!String.IsNullOrEmpty(context.Request.QueryString["callback"])) { return(ProcessJsonpRequest(context, payload)); } context.Response.ContentType = JsonUtility.JsonMimeType; return(context.Response.End(JsonSerializer.Stringify(payload))); }
public void ProtocolResolvesCorrectly(string minProtocol, string maxProtocol, string clientProtocol, string expectedProtocol) { var request = new Mock <IRequest>(); var queryStrings = new NameValueCollection(); var minProtocolVersion = new Version(minProtocol); var maxProtocolVersion = new Version(maxProtocol); var protocolResolver = new ProtocolResolver(minProtocolVersion, maxProtocolVersion); queryStrings.Add("clientProtocol", clientProtocol); request.Setup(r => r.QueryString).Returns(new NameValueCollectionWrapper(queryStrings)); var version = protocolResolver.Resolve(request.Object); Assert.Equal(version, new Version(expectedProtocol)); }
public void ProtocolResolvesCorrectly(string minProtocol, string maxProtocol, string clientProtocol, string expectedProtocol) { var minProtocolVersion = new Version(minProtocol); var maxProtocolVersion = new Version(maxProtocol); var protocolResolver = new ProtocolResolver(minProtocolVersion, maxProtocolVersion); var queryStrings = new Dictionary <string, string> { { "clientProtocol", clientProtocol } }; var context = new TestContext("/negotite", queryStrings); var version = protocolResolver.Resolve(context.MockRequest.Object); Assert.Equal(version, new Version(expectedProtocol)); }
private Task <NegotiateResponse> ProcessNegotiationRequest(HostContext context) { // Total amount of time without a keep alive before the client should attempt to reconnect in seconds. var keepAliveTimeout = _configurationManager.KeepAliveTimeout(); string connectionId = Guid.NewGuid().ToString("d"); string connectionToken = connectionId + ':' + GetUserIdentity(context); var response = new NegotiateResponse(context.Request.LocalPath.Replace("/negotiate", ""), ProtectedData.Protect(connectionToken, Purposes.ConnectionToken), connectionId, keepAliveTimeout?.TotalSeconds, _configurationManager.DisconnectTimeout.TotalSeconds, _configurationManager.ConnectionTimeout.TotalSeconds, _transportManager.SupportsTransport(WebSocketsTransportName) && context.Environment.SupportsWebSockets(), _protocolResolver.Resolve(context.Request).ToString(), _configurationManager.TransportConnectTimeout.TotalSeconds, _configurationManager.LongPollDelay.TotalSeconds); return(SendJsonResponse(context, JsonSerializer.Stringify(response)).ContinueWith(t => response)); }
private Task ProcessNegotiationRequest(HttpContext context) { // Total amount of time without a keep alive before the client should attempt to reconnect in seconds. var keepAliveTimeout = _options.Transports.KeepAliveTimeout(); string connectionId = Guid.NewGuid().ToString("d"); string connectionToken = connectionId + ':' + GetUserIdentity(context); var payload = new { Url = context.Request.LocalPath().Replace("/negotiate", ""), ConnectionToken = ProtectedData.Protect(connectionToken, Purposes.ConnectionToken), ConnectionId = connectionId, KeepAliveTimeout = keepAliveTimeout != null ? keepAliveTimeout.Value.TotalSeconds : (double?)null, DisconnectTimeout = _options.Transports.DisconnectTimeout.TotalSeconds, // TODO: Supports websockets TryWebSockets = _transportManager.SupportsTransport(WebSocketsTransportName) && context.GetFeature <IHttpWebSocketFeature>() != null, ProtocolVersion = _protocolResolver.Resolve(context.Request).ToString(), TransportConnectTimeout = _options.Transports.TransportConnectTimeout.TotalSeconds, LongPollDelay = _options.Transports.LongPolling.PollDelay.TotalSeconds }; return(SendJsonResponse(context, JsonSerializer.Stringify(payload))); }