Transform or middleware for modifying response bodies #2389
-
I'm looking to modify a JSON response body before proxying it back to our client and first did this in a middleware. However after reading you documentation about what not to do in middleware it seems response modification is not advised in middleware. https://microsoft.github.io/reverse-proxy/articles/middleware.html#what-not-to-do-with-middleware I then read your section on response body transforms where response modification didn't seem to be discouraged as much https://microsoft.github.io/reverse-proxy/articles/transforms.html#request-body-transforms My question therefore is whether there it would be better to use middleware or a request body transform for this sort of modification?Or is there not really a difference? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Transforms are a little better because the content has to be copied from the HttpResponseMessage to the HttpResponse anyways, so inserting yourself in there isn't adding an extra step. If you can do the transformation in a streaming fashion (processing a bit at a time rather than reading the whole thing into memory) that's even better. |
Beta Was this translation helpful? Give feedback.
Transforms are a little better because the content has to be copied from the HttpResponseMessage to the HttpResponse anyways, so inserting yourself in there isn't adding an extra step. If you can do the transformation in a streaming fashion (processing a bit at a time rather than reading the whole thing into memory) that's even better.