Allow an IFunctionFilter to modify the HTTP status code/response
See original GitHub issueIFunctionFilter
(and in particular IFunctionInvocationFilter
) seems to be the only mechanism by which the execution pipeline of a function can be modified in a cross-cutting way (since you can’t really access the host builder to add arbitrary middleware).
As such, it would be very useful if the filters could affect the resulting status code of a request (say in an HTTP-triggered function).
A concrete example would be checking for certain headers or access token claims, to determine if the caller has the right permissions for the invocation, and return a 401 or 403 as appropriate.
Currently, the only way to stop/abort the processing of the current request is to throw an exception from the filter, but this results in a fixed 500 error reported to the client.
Potential solutions
- Special-case a new
HttpFunctionException
which can provide a status code and optional status string/message, and in this case it would not be reported as a function failure. - Extend the
FunctionExecutingContext
to allow the filter to signal whether further processing should happen or if it should be stopped (and with that HTTP status code result)
Potential issues
It’s obvious that not all function invocations are HTTP-triggered, so maybe this should only be applied to those. There would need to be a mechanism in the filter to check the type of function being invoked. Currently the FunctionFilterContext
is not sufficiently expressive to accomodate general-purpose pipelines that can act differently depending on the current invocation features/metadata/descriptor. Perhaps the IFunctionExecutionFeature
should be exposed somehow? Maybe just the FunctionDescriptor
?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:12 (1 by maintainers)
Top GitHub Comments
You could inject IHttpContextAccessor into your IFunctionFilter implementation. The property HttpContext should allow you to modify the response. Kind regards
Can you suggest how can we abort the exception in IFunctionExceptionFilter?