C# Class Woopsa.RouteSolver

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.

ファイルを表示 Open project: woopsa-protocol/Woopsa Class Usage Examples

Public Methods

Method Description
Add ( string route, HTTPMethod methods, HandleRequestDelegate handlerMethod, bool acceptSubroutes = false ) : RouteMapper

Adds a route handler for the specified route and HTTP methods, using a delegate.

This is useful for quick, one-off serving of pages. For more complex cases, such as serving files from the file system, it is recommended to use the slightly more complex IHTTPRouteHandler interface.

Add ( string route, HTTPMethod methods, IHTTPRouteHandler handler ) : RouteMapper

Adds a route handler for the specified route and HTTP methods, using a class that implements the IHTTPRouteHandler delegate.

Remove ( RouteMapper routeMapper ) : bool
Remove ( string route ) : bool

Protected Methods

Method Description
OnError ( RoutingErrorType errorType, string message, HTTPRequest request ) : void

Private Methods

Method Description
HandleRequest ( HTTPRequest request, HTTPResponse response, Stream stream ) : void
RouteSolver ( ) : System

Method Details

Add() public method

Adds a route handler for the specified route and HTTP methods, using a delegate.

This is useful for quick, one-off serving of pages. For more complex cases, such as serving files from the file system, it is recommended to use the slightly more complex IHTTPRouteHandler interface.

public Add ( string route, HTTPMethod methods, HandleRequestDelegate handlerMethod, bool acceptSubroutes = false ) : RouteMapper
route string The route, for example "/hello_world"
methods HTTPMethod /// The HTTP Methods to support. HTTPMethod has the [Flag] metadata, /// which makes it possible to support multiple methods in a single page. ///
handlerMethod HandleRequestDelegate A method delegate. See for usage.
acceptSubroutes bool
return RouteMapper

Add() public method

Adds a route handler for the specified route and HTTP methods, using a class that implements the IHTTPRouteHandler delegate.
public Add ( string route, HTTPMethod methods, IHTTPRouteHandler handler ) : RouteMapper
route string The route, for example "/hello_world"
methods HTTPMethod /// The HTTP Methods to support. HTTPMethod has the [Flag] metadata, /// which makes it possible to support multiple methods in a single page. ///
handler IHTTPRouteHandler An object which implements the interface
return RouteMapper

OnError() protected method

protected OnError ( RoutingErrorType errorType, string message, HTTPRequest request ) : void
errorType RoutingErrorType
message string
request HTTPRequest
return void

Remove() public method

public Remove ( RouteMapper routeMapper ) : bool
routeMapper RouteMapper
return bool

Remove() public method

public Remove ( string route ) : bool
route string
return bool