namespace Uwaa.HTTP.Routing; /// /// Parses a path and generates or acquires a response. /// public abstract class RouterBase { /// /// Which HTTP method the router will respond to. /// public abstract HttpMethod Method { get; } /// /// The minimum number of path segments required to produce a response. /// public abstract int Arguments { get; } public Task GetResponse(HttpRequest req, HttpClientInfo info, ArraySegment path) { HttpMethod method = Method; if (method != HttpMethod.Any && req.Method != method) return Task.FromResult(null); int arguments = Arguments; if (path.Count < arguments) return Task.FromResult(null); return GetResponseInner(req, info, path); } /// /// Inline method for routing. /// /// The request for which the response is being generated. /// Information about the client. /// The path segments relevant to the router. protected abstract Task GetResponseInner(HttpRequest req, HttpClientInfo info, ArraySegment path); }