public EventSource(Uri uri) { this.Uri = uri; this.ReconnectionTime = TimeSpan.FromMilliseconds(2000); this.ConnectionKey = new HostConnectionKey(this.Uri.Host, HostDefinition.GetKeyFor(this.Uri #if !BESTHTTP_DISABLE_PROXY , HTTPManager.Proxy #endif )); #if !UNITY_WEBGL || UNITY_EDITOR this.InternalRequest = new HTTPRequest(Uri, HTTPMethods.Get, true, true, OnRequestFinished); // Set headers this.InternalRequest.SetHeader("Accept", "text/event-stream"); this.InternalRequest.SetHeader("Cache-Control", "no-cache"); this.InternalRequest.SetHeader("Accept-Encoding", "identity"); this.InternalRequest.StreamChunksImmediately = true; this.InternalRequest.OnStreamingData = OnData; // Disable internal retry this.InternalRequest.MaxRetries = 0; #else if (!ES_IsSupported()) { throw new NotSupportedException("This browser isn't support the EventSource protocol!"); } this.Id = ES_Create(this.Uri.ToString(), WithCredentials, OnOpenCallback, OnMessageCallback, OnErrorCallback); EventSources.Add(this.Id, this); #endif }
private static HostConfiguration GetHostConfiguration(HostDefinition host) { var hostConfiguration = new HostConfiguration { Host = host.Host }; var port = (ushort)(host.Port != null ? (ushort)host.Port.Value : 0); if (port > 0) { hostConfiguration.Port = port; } Enum.TryParse(host.SslPolicyErrors, out SslPolicyErrors sslPolicyErrors); if (!host.Ssl) { return(hostConfiguration); } hostConfiguration.Ssl.CertPassphrase = host.SslCertPassPhrase; hostConfiguration.Ssl.AcceptablePolicyErrors = sslPolicyErrors; hostConfiguration.Ssl.ServerName = host.SslServerName; hostConfiguration.Ssl.CertPath = FileOperations.GetFileFullPath(host.SslCertPath); hostConfiguration.Ssl.Enabled = host.Ssl; return(hostConfiguration); }
private static bool ShouldAddToSiteHosts(HostDefinition host, SiteDefinition siteInformation) { if (host.Name == "*") { return(false); } return(!UriComparer.SchemeAndServerEquals(host.GetUri(), siteInformation.SiteUrl)); }
public void WriteTo(string recipeName, HostDefinition host, DeploymentSettings settings) { var fileName = settings.GetHost(recipeName, host.Name); host.References.Each(WriteReference); host.Values.Each(WritePropertyValue); host.Directives.Each(WriteDirective); _fileSystem.WriteStringToFile(fileName, ToText()); }
public static Uri GetUri(this HostDefinition host) { var scheme = "http"; if (host.UseSecureConnection != null && host.UseSecureConnection == true) { scheme = "https"; } var hostUrl = $"{scheme}://{host.Name}/"; return(new Uri(hostUrl)); }
public List <HostDefinition> ToHostDefinitions() { var hostDefinitions = new List <HostDefinition>(); foreach (HostElement element in this) { var hostDefinition = new HostDefinition { Name = element.Name, Type = element.Type != HostDefinitionType.Undefined ? element.Type : HostDefinitionType.Undefined, UseSecureConnection = element.UseSecureConnection, Language = string.IsNullOrEmpty(element.Language) ? null : new CultureInfo(element.Language) }; hostDefinitions.Add(hostDefinition); } return(hostDefinitions); }
public void Can_Retrieve_SiteMapData_By_URL_When_SiteMapData_SiteUrl_Is_Null() { var requestUrl = "https://www.domain.com/en/sitemap.xml"; var expectedSitemapData = new SitemapData { Language = "en", Host = "Sitemap.xml", SiteUrl = null }; var hostDefinition = new HostDefinition(); var siteDefinition = new SiteDefinition(); siteDefinition.Hosts = new List <HostDefinition> { new HostDefinition { Name = "www.domain.com" } }; var siteDefinitionResolver = new Mock <ISiteDefinitionResolver>(); siteDefinitionResolver .Setup(x => x.GetByHostname(It.IsAny <string>(), It.IsAny <bool>(), out hostDefinition)) .Returns(siteDefinition); var sitemapDataList = new List <SitemapData> { expectedSitemapData }; var sitemapLoader = new Mock <ISitemapLoader>(); sitemapLoader .Setup(x => x.GetAllSitemapData()) .Returns(sitemapDataList); var siteMapService = new SitemapRepository(_languageBranchRepository.Object, siteDefinitionResolver.Object, sitemapLoader.Object); var siteMapData = siteMapService.GetSitemapData(requestUrl); Assert.Equal(siteMapData, expectedSitemapData); }
public void One_Host_And_Multiple_Sitemaps_Can_Retrieve_Correct_SiteMap(string[] siteMapUrls, string requestedHostURL) { var requestUrl = $"{requestedHostURL}/en/sitemap.xml"; var sitemapDataList = siteMapUrls.Select(x => new SitemapData { Language = "en", Host = "Sitemap.xml", SiteUrl = x }).ToList(); var expectedSitemapData = sitemapDataList.FirstOrDefault(x => x.SiteUrl.Equals(requestedHostURL)); var hostDefinition = new HostDefinition(); var siteDefinition = new SiteDefinition(); siteDefinition.Hosts = new List <HostDefinition> { new HostDefinition { Name = new Uri(requestedHostURL, UriKind.Absolute).Authority } }; var siteDefinitionResolver = new Mock <ISiteDefinitionResolver>(); siteDefinitionResolver .Setup(x => x.GetByHostname(It.IsAny <string>(), It.IsAny <bool>(), out hostDefinition)) .Returns(siteDefinition); var sitemapLoader = new Mock <ISitemapLoader>(); sitemapLoader .Setup(x => x.GetAllSitemapData()) .Returns(sitemapDataList); var siteMapService = new SitemapRepository(_languageBranchRepository.Object, siteDefinitionResolver.Object, sitemapLoader.Object); var siteMapData = siteMapService.GetSitemapData(requestUrl); Assert.True(siteMapData != null); Assert.Equal(siteMapData, expectedSitemapData); }
internal WebSocketResponse(HTTPRequest request, Stream stream, bool isStreamed, bool isFromCache) : base(request, stream, isStreamed, isFromCache) { base.IsClosedManually = true; this.ConnectionKey = new HostConnectionKey(this.baseRequest.CurrentUri.Host, HostDefinition.GetKeyForRequest(this.baseRequest)); closed = false; MaxFragmentSize = UInt16.MaxValue / 2; }