public static IDisposable Create(AppFunc app, IDictionary <string, object> properties) { if (app == null) { throw new ArgumentNullException("app"); } if (properties == null) { throw new ArgumentNullException("properties"); } // Retrieve the instances created in Initialize OwinHttpListener wrapper = properties.Get <OwinHttpListener>(typeof(OwinHttpListener).FullName) ?? new OwinHttpListener(); System.Net.HttpListener listener = properties.Get <System.Net.HttpListener>(typeof(System.Net.HttpListener).FullName) ?? new System.Net.HttpListener(); IList <IDictionary <string, object> > addresses = properties.Get <IList <IDictionary <string, object> > >("host.Addresses") ?? new List <IDictionary <string, object> >(); IDictionary <string, object> capabilities = properties.Get <IDictionary <string, object> >(Constants.ServerCapabilitiesKey) ?? new Dictionary <string, object>(); LoggerFactoryFunc loggerFactory = properties.Get <LoggerFactoryFunc>("server.LoggerFactory"); wrapper.Start(listener, app, addresses, capabilities, loggerFactory); return(wrapper); }
internal static LoggerFunc CreateLogger(LoggerFactoryFunc factory, Type type) { if (factory == null) { return(null); } return(factory(type.FullName)); }
internal static LoggerFunc CreateLogger(LoggerFactoryFunc factory, Type type) { if (factory == null) { return null; } return factory(type.FullName); }
/// <summary> /// Starts the listener and request processing threads. /// </summary> internal void Start(System.Net.HttpListener listener, AppFunc appFunc, IList <IDictionary <string, object> > addresses, IDictionary <string, object> capabilities, LoggerFactoryFunc loggerFactory) { Contract.Assert(_appFunc == null); // Start should only be called once Contract.Assert(listener != null); Contract.Assert(appFunc != null); Contract.Assert(addresses != null); _listener = listener; _appFunc = appFunc; _loggerFactory = loggerFactory; if (_loggerFactory != null) { _logger = _loggerFactory(typeof(OwinHttpListener).FullName); } _basePaths = new List <string>(); foreach (var address in addresses) { // build url from parts string scheme = address.Get <string>("scheme") ?? Uri.UriSchemeHttp; string host = address.Get <string>("host") ?? "localhost"; string port = address.Get <string>("port") ?? "5000"; string path = address.Get <string>("path") ?? string.Empty; // if port is present, add delimiter to value before concatenation if (!string.IsNullOrWhiteSpace(port)) { port = ":" + port; } // Assume http(s)://+:9090/BasePath/, including the first path slash. May be empty. Must end with a slash. if (!path.EndsWith("/", StringComparison.Ordinal)) { // Http.Sys requires that the URL end in a slash path += "/"; } _basePaths.Add(path); // add a server for each url string url = scheme + "://" + host + port + path; _listener.Prefixes.Add(url); } _capabilities = capabilities; _disconnectHandler = new DisconnectHandler(_listener); if (!_listener.IsListening) { _listener.Start(); _disconnectHandler.Initialize(); } OffloadStartNextRequest(); }
/// <summary> /// Starts the listener and request processing threads. /// </summary> internal void Start(System.Net.HttpListener listener, AppFunc appFunc, IList<IDictionary<string, object>> addresses, IDictionary<string, object> capabilities, LoggerFactoryFunc loggerFactory) { Contract.Assert(_appFunc == null); // Start should only be called once Contract.Assert(listener != null); Contract.Assert(appFunc != null); Contract.Assert(addresses != null); _listener = listener; _appFunc = appFunc; _loggerFactory = loggerFactory; if (_loggerFactory != null) { _logger = _loggerFactory(typeof(OwinHttpListener).FullName); } _basePaths = new List<string>(); foreach (var address in addresses) { // build url from parts string scheme = address.Get<string>("scheme") ?? Uri.UriSchemeHttp; string host = address.Get<string>("host") ?? "localhost"; string port = address.Get<string>("port") ?? "5000"; string path = address.Get<string>("path") ?? string.Empty; // if port is present, add delimiter to value before concatenation if (!string.IsNullOrWhiteSpace(port)) { port = ":" + port; } // Assume http(s)://+:9090/BasePath/, including the first path slash. May be empty. Must end with a slash. if (!path.EndsWith("/", StringComparison.Ordinal)) { // Http.Sys requires that the URL end in a slash path += "/"; } _basePaths.Add(path); // add a server for each url string url = scheme + "://" + host + port + path; _listener.Prefixes.Add(url); } _capabilities = capabilities; _disconnectHandler = new DisconnectHandler(_listener); if (!_listener.IsListening) { _listener.Start(); _disconnectHandler.Initialize(); } OffloadStartNextRequest(); }