public virtual Task ProcessRequest(HttpContext context, Func<Task> next)
{
//Keep in sync with Kestrel/AppSelfHostBase.cs
var operationName = context.Request.GetOperationName().UrlDecode() ?? "Home";
var pathInfo = context.Request.Path.HasValue
? context.Request.Path.Value
: "/";
var mode = Config.HandlerFactoryPath;
if (!string.IsNullOrEmpty(mode))
{
if (pathInfo.IndexOf(mode, StringComparison.Ordinal) != 1)
return next();
pathInfo = pathInfo.Substring(mode.Length + 1);
}
var httpReq = new NetCoreRequest(context, operationName, RequestAttributes.None, pathInfo);
httpReq.RequestAttributes = httpReq.GetAttributes();
var httpRes = httpReq.Response;
var handler = HttpHandlerFactory.GetHandler(httpReq);
var serviceStackHandler = handler as IServiceStackHandler;
if (serviceStackHandler != null)
{
if (serviceStackHandler is NotFoundHttpHandler)
return next();
if (!string.IsNullOrEmpty(serviceStackHandler.RequestName))
operationName = serviceStackHandler.RequestName;
var restHandler = serviceStackHandler as RestHandler;
if (restHandler != null)
{
httpReq.OperationName = operationName = restHandler.RestPath.RequestType.GetOperationName();
}
var task = serviceStackHandler.ProcessRequestAsync(httpReq, httpRes, operationName);
task.ContinueWith(x => httpRes.Close(), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);
//Matches Exceptions handled in HttpListenerBase.InitTask()
return task;
}
return next();
}