public DynamicRouteManager(LoggingManager logging, bool debug) { if (logging == null) { throw new ArgumentNullException(nameof(logging)); } Logging = logging; Debug = debug; RegexMatch = new Matcher(); }
public StaticRouteManager(LoggingManager logging, bool debug) { if (logging == null) { throw new ArgumentNullException(nameof(logging)); } Logging = logging; Debug = debug; Routes = new List <StaticRoute>(); RouteLock = new object(); }
public ContentRouteProcessor(LoggingManager logging, bool debug, ContentRouteManager routes) { if (logging == null) { throw new ArgumentNullException(nameof(logging)); } if (routes == null) { throw new ArgumentNullException(nameof(routes)); } Logging = logging; Debug = debug; Routes = routes; }
/// <summary> /// Creates a new instance of the Watson Webserver. /// </summary> /// <param name="ip">IP address on which to listen.</param> /// <param name="port">TCP port on which to listen.</param> /// <param name="ssl">Specify whether or not SSL should be used (HTTPS).</param> /// <param name="defaultRequestHandler">Method used when a request is received and no routes are defined. Commonly used as the 404 handler when routes are used.</param> public Server(string ip, int port, bool ssl, Func <HttpRequest, HttpResponse> defaultRequestHandler, bool debug) { if (String.IsNullOrEmpty(ip)) { ip = "*"; } if (port < 1) { throw new ArgumentOutOfRangeException(nameof(port)); } if (defaultRequestHandler == null) { throw new ArgumentNullException(nameof(defaultRequestHandler)); } Http = new HttpListener(); ListenerIp = ip; ListenerPort = port; ListenerSsl = ssl; Logging = new LoggingManager(debug); if (debug) { DebugRestRequests = true; DebugRestResponses = true; } DynamicRoutes = new DynamicRouteManager(Logging, debug); StaticRoutes = new StaticRouteManager(Logging, debug); ContentRoutes = new ContentRouteManager(Logging, debug); ContentProcessor = new ContentRouteProcessor(Logging, debug, ContentRoutes); DefaultRoute = defaultRequestHandler; OptionsRoute = null; Console.Write("Starting Watson Webserver at "); if (ListenerSsl) { Console.WriteLine("https://" + ListenerIp + ":" + ListenerPort); } else { Console.WriteLine("http://" + ListenerIp + ":" + ListenerPort); } TokenSource = new CancellationTokenSource(); Token = TokenSource.Token; Task.Run(() => StartServer(Token), Token); }