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

Satyam Agarwal

06/08/2022, 10:45 AM
Hei, Just curious why content is marked as internal ? When used together with ResponseObserver, Then I have to use OptIn internal api annotation. I use ResponseObserver to log response body. I donot want to use bodyAsChannel, as it may contain modified response. https://github.com/ktorio/ktor/blob/main/ktor-client/ktor-client-core/common/src/io/ktor/client/statement/HttpResponse.kt#L55-L56
a

Aleksei Tirman [JB]

06/08/2022, 10:46 AM
@Rustam Siniukov
r

Rustam Siniukov

06/08/2022, 10:52 AM
Because
content
is raw response and we want to discourage its usage. If you know what you do, just use
@OptIn
, should be safe.
s

Satyam Agarwal

06/08/2022, 10:56 AM
Are there plans to expose it in some other way then, I mean raw response in combination with ResponseObserver is especially helpful
r

Rustam Siniukov

06/08/2022, 11:04 AM
If we get more use cases to come up with a good API for it, then yes.
s

Satyam Agarwal

06/08/2022, 11:06 AM
Okay. With the risk of being a little pushy, doesn’t the motivation of
ResponseObserver
class remains incomplete if one cannot observer complete response (meaning, reading the response body, and perhaps using it in the handler) ?
Could ResponseObserver then provide, httpResponse, and content as predicates to the handler, so we can use it in our cases ?
just like
ResponseBodyReadyForSend
Hook ? (a server hook I know, but pointing it out as a feature)
r

Rustam Siniukov

06/08/2022, 11:11 AM
No worries, explaining your use cases is always welcome! In this case we will make it really easy to access raw body, which is usually discouraged. Imagine you have gzip encoding in your response. There is not much sense in accessing it as it is. But if callback will receive it as a parameter, users will almost for certain try to read it instead of calling
.bodyAsChannel()
Maybe we need to create an annotation similar to
@DangerousApi
in coroutines, and use it here instead of
@InternalApi
.
ResponseBodyReadyForSend
receives processed body with all the transformations applied,
.content
is just bytes that we read from the network
s

Satyam Agarwal

06/09/2022, 6:11 AM
Yeah, that makes sense, just a naive question. Apart from byteBuffer to concrete type transformtion when
.bodyAsChannel
is called, are there other transformations one can expect in HttpResponsePipeline ?
r

Rustam Siniukov

06/09/2022, 11:19 AM
Mostly transforming and content encoding
s

Satyam Agarwal

06/09/2022, 5:47 PM
Thank you 🙂
👍 1
2 Views