https://kotlinlang.org logo
#http4k
Title
# http4k
s

s4nchez

11/25/2018, 12:13 PM
@David Hamilton Here's an example of how to combine list of filters in a functional fashion:
Copy code
val defaultStack = Filter.NoOp.then(ClientFilters.GZip())

    val additionalFilters: List<Filter> = listOf(
        DebuggingFilters.PrintRequestAndResponse(),
        ClientFilters.BasicAuth("user", "pass"))

    // additional after default
    val combinedFilter1: Filter = additionalFilters.fold(defaultStack) { acc, next -> acc.then(next) }
    
    // additional before default
    val combinedFilter2: Filter = additionalFilters.fold(Filter.NoOp) { acc, next -> acc.then(next) }.then(defaultStack)
d

David Hamilton

11/25/2018, 12:18 PM
You even answered the unspoken question of whether the filters should be added before or after the existing stack
s

s4nchez

11/25/2018, 12:21 PM
They can be added in either order. It depends on how your default stack is supposed to be used by each service really
5 Views