I am having to add this
PreRequestFilter to my AppHost because I have an
HmacAuthProvider : IAuthWithRequest that needs to call
PreRequestFilters.Insert(0, (req, res) =>
req.UseBufferedStream = true;
I am not sure what the side-effects of
IRequest.UseBufferedStream = true are on the other operations and services in my service, since the default is:
IRequest.UseBufferedStream = false
So I would like to limit any effects on other service operations.
So my question is: is it possible to somehow limit which kinds of requests I set
IRequest.UseBufferedStream = true on?
I know I cannot look at the
IRequest.Dto, because it is not yet deserialised when a
PreRequestFilter is run.
But I can say that the only DTO's and service operations for which this is only relevant to are known and contained in a single service.
What would be the next best way to tell whether the request is bound for a specific service, operation or DTO?
There shouldn't be any effect other than the performance of keeping a copy of the Request Body in a MemoryStream so it can be reread.
You can inspect the Request DTO Type with
Turns out that
null in a PreRequestFilter!
Actually , is there anyway to tell what service the current request is bound for, rather than the type of the request?
Or even better, tell whether the DTO has a specific
AuthenticateAttribute on it?
The only requests that needs this filter are in a single service, and they all look like this:
public void Post(MyDto1 body)
public void Get(MyDto2 body)
You need the Request Type of the Request to find out what the Service Type is, e.g:
var serviceType = HostContext.Metadata.GetServiceTypeByRequest(requestType);
You can try looking up the Route manually with:
var restPath = HostContext.ServiceController.GetRestPathForRequest(httpReq.Verb, httpReq.PathInfo);
var requestType = restPath.RequestType;
BTW you can just annotate your Service once, instead of each Service individually, e.g:
public class MyAuthServices : Service
public void Post(MyDto1 body) => ...;
public void Get(MyDto2 body) => ...;
req.GetRoute() should now be available in Pre Request Filters in v4.5.9 that's now on MyGet.