-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can middleware access/alter what was returned from the function? #340
Comments
@godefroi that's the goal, but some of that information is not yet exposed in the context that flows with the invocation. We have upcoming API reviews to cover items like binding data (which will be accessible in the binding context), function activation and other items are included in that list as well. |
Thanks, I appreciate the answer. It's looking good, and while we're clearly not at a final product yet, I like the direction. |
Thank you! We'll definitely be lighting a lot these things up as we go, and feedback like like helps us prioritize what should come first. |
It's a shame that modification of output was possible in the preview4 and is not in the 1.0.0, I've prepared a code which does that in the preview. And that is rendered completely useless since it's not even a matter or rewriting it, rather than inability to perform such action at all. Unless there's some kind of way of doing so by any chance after the middleware was called, even via (ugh) reflection? (want to solve this at least for a now) As I was not able to detect one as such. |
It will be good if we can also access the input parameters from the middleware. |
@josere that is part of the plan. The goal is to enable scenarios where middleware can inspect and modify input and output data associated with the context. |
+1 on this one! I had the same use case of global error handling, etc. |
I was super excited to update to the new out-of-process model simply for the sake of being able to run middlewares. We largely use(d) Another use-case I was hoping to convert was the addition of a [Function(nameof(Health))]
public async Task<HttpResponseData> Health
(
[HttpTrigger(AuthorizationLevel.Anonymous, nameof(HttpMethods.Get), Route = "health")]
HttpRequestData request
)
{
HttpResponseData response = request.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(new {DateTime.UtcNow});
return response;
} This is perfect for a middleware so we can eliminate the code redundancy but, alas, we can't terminate the pipeline. Please prioritize gaining access to |
Has there been any movement for this, or is there any workaround for this? |
@defunky there is work around to read the HttpResponseData returned from the Fx in middleware. check this out #414 (comment) |
@lohithgn that seems to be related to HttpRequestData not HttpResponseData. Edit: although you can do a similar thing and set the InvocationResult via reflection and it seems to work. Thanks for the heads up |
Any idea how to do this? I can only see the incoming http headers, not the out going. |
@rhollamby
You can probably to similar thing but instead of setting InvocationResult you can try retrieving it with reflection if you want to see what the result was but I haven't tried it. |
|
Is this still in progress >? |
Yes, we are currently working on this item. The new APIs to support reading & altering input and output data from middleware will be available in the next few weeks. I will share an update to this thread as we make progress. Thanks! |
@kshyju So, your last comment was more than two months ago, do you have a status update? |
Couldn't you change the HttpResponse with the IFunctionFilters? |
@stephanruhland @godefroi hope you don't mind me chiming in here... I would personally be hesitant to use function Filters as they're marked deprecated/Not GA and also it doesn't look like they can, yet: Azure/azure-webjobs-sdk#1314 I might be speaking out of turn here as I regularly get mixed up with worker versus hosted and the sdks etc. =) |
And, not all functions are HTTP triggered. So the semantics have to work with triggers other than HTTP. |
Version 1.8.0-preview1 of
Usage samples:
Hope this helps. Let us know if you have any questions. |
If I test the first sample in an attempt to build an authroization middleware I get this response back from the HTTP trigger: { The HTTP status code is also 200. Trying to set the status code on the newResponse has only an affect on the body. Not on the status code of the http response. `
` What am I doing wrong? |
I'm putting together a global exception-handling middleware, and I'd like to be able to alter what will be returned for the output binding. The example middleware only puts data into the
Items
collection; I'm wondering if there's an example anywhere for accessing or manipulating the output binding data?The text was updated successfully, but these errors were encountered: