How to define Response Filter Attribute for requests with void return type


I’ve implemented a session timeout sliding as ResponseFilterAttribute. After implementing a simple “keep alive” GET request that doesn’t return a value, I found out that the code in my attribute isn’t invoked.

A short investigation showed that if I add any data to response (I added a string), the response filter code is triggered.

Please, advise how can I define a response filter attribute for service methods that don’t return values.

Thank you

Empty/null responses aren’t executed in Response Filters. You can handle them by overriding OnAfterExecute() in your AppHost.

Also note GET’s (by HTTP Contract) should be idempotent and side-effect free, not returning anything is an indication that it’s not.

I’ve change the request to be POST request. It receives DTO without fields and returns void.
The effect is the same: Response Filter isn’t triggered.

I know which is why I said:

Sorry. I thought it is addressing only GET requests which are expected to return data.

It means that I can replace all void server API methods with returning string and return the empty string to enforce it invoking the response filter attribute, correct?

Yes returning anything will execute the response filters.