Is it possible a feature/plugin depends on another...
# ktor
j
Is it possible a feature/plugin depends on another?
e
For ktor client's plugin I used/created, I don't think there's a direct approach to impl this. But if u look into their implementations, can see the interceptor pipelines - base on the lifecycle of those pipeline, u can define the running sequence and thus make dependent relationship indirectly.
j
I need to transform the type with my feature before JsonFeature get it.
Copy code
@Serializable
data class User

@Serializable
data class SomeError

client.get<Either<SomeError, User>>(...)
The problem is JsonFeature should be able to parse SomeError or User, so I have to unwrap it from my Either before, if not, JsonFeature will try it with the Either class and it will fail
e
Probably u can use HttpResponsePipeline.Receive in your custom plugin to unwrap before JsonFeature works.
Copy code
scope.responsePipeline.intercept(HttpResponsePipeline.Receive) { (info, body) ->
    if (body !is ByteReadChannel) { return @intercept}
    // Do something you want and get the final result in String (others types I did not try)
    val result: String = decrypt(body.readRemaining().readText())
    proceedWith(HttpResponseContainer(info, ByteReadChannel(result)))
}
j
I will try, thank you 🙂
e
Updated my code, I used it in my project to decrypt encoded Json Strings before JsonFeature.
j
But it let changing the type that JsonFeature will receive?
e
Well.. from the JsonFeature it does not aware our interceptor, so it reads http response from the ByteReadChannel (Kinda byte stream or something similar) always.