public TestHttpListener(IConfigurationSource configuration) { // TODO: On windows, anyone can listen on port 80 at Temporary_Listen_Addresses // TODO: On Mono, not the case. So we probably need different logic for windows/mono // TODO: otherwise you need to be Admin to run these tests on Windows AppPathVDir = $"Temporary_Listen_Addresses/{Guid.NewGuid()}/"; var isStarting = true; do { try { Port = Random.Next(2048, 4096); Host = new HttpListenerHost(configuration); Host.Initialize(new[] { $"http://+:{Port}/{AppPathVDir}" }, AppPathVDir, null); Host.StartListening(); isStarting = false; } catch { // Ignore } } while (isStarting); }
public void the_results_should_be_the_same_instance() { var host = new HttpListenerHost(); host.Initialize(new[] { "http://+:" + PORT + "/" }, "/", typeof(DependencyResolverAccessorStub)); var instance1 = host.ResolverAccessor; var instance2 = host.ResolverAccessor; instance1.ShouldBeTheSameInstanceAs(instance2); }
public when_creating_a_new_HttpListenerHost_with_WindsorResolver() { // init container _container = new WindsorContainer(); var port = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 18981 : randomPort.Next(1024, 2048); Prefix = $"http://localhost:{port}/"; _container.Register( Component.For <IConfigurationSource>().ImplementedBy <TestConfigurationSource>().LifestyleSingleton()); _host = new HttpListenerHost(new TestConfigurationSource(), new WindsorDependencyResolver(_container)); _host.Initialize(new[] { Prefix }, "/"); _host.StartListening(); }
static void Main(string[] args) { ServicePointManager.DefaultConnectionLimit = 144; ThreadPool.SetMinThreads(100, 100); ThreadPool.SetMaxThreads(250, 250); var config = new Configuration(); using (var host = new HttpListenerHost(config, config.Resolver)) { host.Initialize(new[] { "http://localhost:9070/" }, string.Empty); host.StartListening(); Console.WriteLine("Press any key to stop listening..."); Console.ReadKey(true); host.StopListening(); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); }
public exception_with_logging_from_http_listener_host() { _fakeLogger = new FakeLogger(); var appPathVDir = $"Temporary_Listen_Addresses/{Guid.NewGuid()}/"; var started = false; int port = -1; do { try { port = _random.Next(2048, 4096); _httpListenerHost = new HttpListenerHost(new Configuration(_fakeLogger)); _httpListenerHost.Initialize(new[] { $"http://+:{port}/{appPathVDir}" }, appPathVDir, null); _httpListenerHost.StartListening(); started = true; } catch { } } while (!started); using (var webClient = new WebClient()) { try { webClient.DownloadString($"http://localhost:{port}/{appPathVDir}"); } catch (WebException e) { _response = (HttpWebResponse)e.Response; } } }
public override void Initialize() { _host = new HttpListenerHostWithConfiguration(new Configurator()); _host.Initialize(new[] { "http://+:" + Port + "/" }, "/", null); _host.StartListening(); }