Make body filters aware if they are dealing with a request or response
nhmarujo opened this issue ยท 8 comments
It would be great if we could have more context on body filters, like if we are dealing with a request or a response. That would allow us to take better decisions. For instance, imagine you have an API on which you wanna disable all response logging cause the payloads are too big, you could just check for a property. I realise this can also be done checking for a max-size but in some cases the flag would probably be more efficient. This is obviously just an example, there may be many more use cases.
Of course I do realise that just request/response awareness is not enough, because there is the potential to log bot server and client calls. For that origin
awareness would also be useful.
Thanks
I think it can be helpful to make the right filtering decision if it had more context. As you mentioned, at least to know if it's a request/response and what's the origin.
As per the example you mentioned, I understand it's just an example, but just to point out that this is already possible. You could use the ResponseFilter
for cases when you want to omit logging the response body based on some conditions. That's what ResponseFilters.defaultValue() is using via BodyReplacers to avoid logging bodies with binary data.
Thank you for the prompt answer @kasmarian . Honestly I was not aware of that, but yes it was just an example. That said I still see value in having more context in filters so that people have more flexibility to make decisions ๐
Would this be something that your team would consider adding?
Thank you
We could have a look, yes, but I can't tell you any timeline promises. If you have time and desire, please feel free to suggest the changes, and we'll review them.
Thanks @kasmarian . Honestly I had no expectations time-wise. More than a matter of time and desire, I'm lacking deeper knowledge on how things are structured. But I will take a look and who knows, if I get some idea I will shared of course ๐ Have a nice weekend!
Was also thinking that it also be good to be aware of the status code, if you are dealing with a response.
A BodyFilter
was meant to be just that, a filter for a message body. If you need more context or want to only apply something for requests but not responses, etc. then I'd argue you should use one of the lower-level abstractions like Request
- or ResponseFilter
.