private HttpHandler SelectHandler(HttpContext context) { Uri absolute = context.Request.RequestedUrl; if (!absolute.IsAbsoluteUri) { absolute = new Uri(context.Request.Host, absolute); } string fileName = absolute.Segments.Last(); string ext = null; if (!fileName.Contains(".")) ext = ".html"; else ext = "." + fileName.Split('.').Last(); HttpHandler handler = null; foreach (var candidate in Handlers) { if (candidate.FileExtensions != null && candidate.FileExtensions.Contains(ext)) { handler = candidate; break; } // candidate is a default (low level) handler, that is better than nothing. if (candidate.FileExtensions == null && handler == null) { handler = candidate; } } if (handler == null) { handler = new HttpHandler(); handler.Host = this; } return handler; }
public async Task HandleRequestAsync(HttpContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); HttpHandler handler = SelectHandler(context); await handler.HandleRequestAsync(context); }