Reputation: 871
question about filter : https://twitter.github.io/scala_school/finagle.html#Filter
For typical stack of filters + service layout, how can I add a default behavior for each of the filters? Which basically look at the request/response and do some side effect actions(counting, logging etc). I don't want to write code for each filter, but rather want to have this default behavior triggered on end of each filter.
Upvotes: 0
Views: 156
Reputation: 14414
What you want is filter composition, i.e. you create a filter that's really just a pass-through and causes some side-effects and then you can mix that in with any other filter via composition. e.g.:
val authFilter: Filter[HttpReq, HttpRep, AuthHttpReq, HttpRep]
val loggingFilter[Req, Rep]: Filter[Req, Rep, Req, Rep]
val authWithLogging: Filter[HttpReq, HttpRep, AuthHttpReq, HttpRep] =
authFilter andThen loggingFilter
Upvotes: 1