AsyncRequestFilters
We are creating a api that uses authorization attribute request filter in all paths(except login, of course). The attribute request for authorization to another system. Because request filters are sync the request is blocked and waiting for response at this point. A solution can be that request filters can returns a Task. Something like this:
public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName){
.....
return Task.Factory.ContinueWhenAll(appHost.ApplyAsyncRequestFilters(httpReq, httpRes, request),
tasks => httpRes.IsClosed ? null : GetResponse(httpReq, request))
.ContinueWith(tResponse => HandleResponse(tResponse.Result, response =>
{
if (appHost.ApplyResponseFilters(httpReq, httpRes, response))
return null;
if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
return WriteDebugResponse(httpRes, response);
if (doJsonp && !(response is CompressedResult))
return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
return httpRes.WriteToResponse(httpReq, response);
},
ex => !HostContext.Config.WriteErrorsToResponse
? ex.AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex)));
}
1
vote

Support for Async Request Filters was added in v4.5.8:
http://docs.servicestack.net/releases/v4.5.8#async-global-request-filters