user776635
user776635

Reputation: 871

finagle filter add default behavior

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

Answers (1)

Arne Claassen
Arne Claassen

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

Related Questions