Provides a mechanism to match a URL with an appropriate response.

The RouteSolver is a solution to the common problem of serving web pages based on the request made by a browser. It's an internal part of the WebServer and thus cannot be created from outside.

The public methods, however, allow the user to add routes to the solver using either delegates for simple cases, or classes that implement the WebServer.IHTTPRouteHandler interface.

Ejemplo n.º 1
0
 /// <summary>
 /// Creates a WebServer that runs on the specified port and can be multithreaded
 /// </summary>
 /// <param name="port">
 /// The port on which to run the server (default 80)
 /// </param>
 /// <param name="threadPoolSize">
 /// The maximum number of threads to be created.
 /// CustomThreadPool.DefaultThreadPoolSize means use default operating system value.
 /// </param>
 /// <param name="priority">
 /// The priority of the web server threads.
 /// </param>
 /// <remarks>
 /// A server must be multithreaded in order to use the Keep-Alive HTTP mechanism.
 /// </remarks>
 public WebServer(int port = DefaultPortHttp, int threadPoolSize = CustomThreadPool.DefaultThreadPoolSize, ThreadPriority priority = DefaultThreadPriority)
 {
     Port = port;
     PreRouteProcessors = new List <PreRouteProcessor>();
     Routes             = new RouteSolver();
     Routes.Error      += _routeSolver_Error;
     _openTcpClients    = new List <TcpClient>();
     _listener          = new TcpListener(IPAddress.Any, port);
     if (threadPoolSize == CustomThreadPool.DefaultThreadPoolSize || threadPoolSize > 1)
     {
         _threadPool = new CustomThreadPool("WoopsaWebServer", threadPoolSize, priority);
     }
     _listenerThread          = new Thread(Listen);
     _listenerThread.Priority = priority;
     _listenerThread.Name     = "WebServer_Listener";
     HTTPResponse.Error      += HTTPResponse_Error;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a WebServer that runs on the specified port and can be multithreaded
 /// </summary>
 /// <param name="port">
 /// The port on which to run the server (default 80)
 /// </param>
 /// <param name="threadPoolSize">
 /// The maximum number of threads to be created. 
 /// CustomThreadPool.DefaultThreadPoolSize means use default operating system value.
 /// </param>
 /// <param name="priority">
 /// The priority of the web server threads.
 /// </param>
 /// <remarks>
 /// A server must be multithreaded in order to use the Keep-Alive HTTP mechanism.
 /// </remarks>
 public WebServer(int port = DefaultPortHttp, int threadPoolSize = CustomThreadPool.DefaultThreadPoolSize, ThreadPriority priority = DefaultThreadPriority)
 {
     Port = port;
     PreRouteProcessors = new List<PreRouteProcessor>();
     Routes = new RouteSolver();
     Routes.Error += _routeSolver_Error;
     _openTcpClients = new List<TcpClient>();
     _listener = new TcpListener(IPAddress.Any, port);
     if (threadPoolSize == CustomThreadPool.DefaultThreadPoolSize || threadPoolSize > 1)
         _threadPool = new CustomThreadPool("WoopsaWebServer", threadPoolSize, priority);
     _listenerThread = new Thread(Listen);
     _listenerThread.Priority = priority;
     _listenerThread.Name = "WebServer_Listener";
     HTTPResponse.Error += HTTPResponse_Error;
 }