public IHttpHandler GetHandler(HttpContext ctx, string requestType, string url, string pathTranslated)
{
var context = ctx.Request.RequestContext.HttpContext;
var appHost = HostContext.AppHost;
DebugLastHandlerArgs = requestType + "|" + url + "|" + pathTranslated;
//var httpReq = new AspNetRequest(context, url);
var httpReq = new ServiceStack.Host.AspNet.AspNetRequest(context, url.SanitizedVirtualPath());
foreach (var rawHttpHandler in appHost.RawHttpHandlers)
{
var reqInfo = rawHttpHandler(httpReq);
if (reqInfo != null) return reqInfo;
}
var mode = appHost.Config.HandlerFactoryPath;
var pathInfo = context.Request.GetPathInfo();
//WebDev Server auto requests '/default.aspx' so recorrect path to different default document
if (mode == null && (url == "/default.aspx" || url == "/Default.aspx"))
pathInfo = "/";
//Default Request /
if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/")
{
//If the fallback route can handle it, let it
if (appHost.Config.FallbackRestPath != null)
{
string contentType;
var sanitizedPath = RestHandler.GetSanitizedPathInfo(pathInfo, out contentType);
var restPath = appHost.Config.FallbackRestPath(context.Request.HttpMethod, sanitizedPath, pathTranslated);
if (restPath != null)
{
return new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.GetOperationName(), ResponseContentType = contentType };
}
}
//Exception calling context.Request.Url on Apache+mod_mono
var absoluteUrl = Env.IsMono ? url.ToParentPath() : context.Request.GetApplicationUrl();
SetApplicationBaseUrl(absoluteUrl);
//e.g. CatchAllHandler to Process Markdown files
var catchAllHandler = GetCatchAllHandlerIfAny(httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath());
if (catchAllHandler != null) return catchAllHandler;
if (mode == null)
return DefaultHttpHandler;
if (DefaultRootFileName != null)
return StaticFilesHandler;
return NonRootModeDefaultHttpHandler;
}
if (mode != null && pathInfo.EndsWith("/" + mode))
{
return ReturnDefaultHandler(httpReq);
}
return GetHandlerForPathInfo(
httpReq.HttpMethod, pathInfo, context.Request.FilePath, pathTranslated)
?? NotFoundHttpHandler;
}
#endif