Colton Idle
08/12/2020, 9:51 PMResponse<MyResponseType>
instead of Response<Void>
and now everything shows in chucker... going to dig a bit more because that does NOT seem right. Even with Response<Void> I should be getting a proper body showing in chucker.
Edit: Yep. Changed back to Response<Void>
and now chucker shows an empty response. This is not how Chuck used to work? Still investigating...MiSikora
08/13/2020, 7:49 PMResponse<Void>
or Response<Unit>
at all and just closes the response body once the response is received. Chucker observes the network traffic that happens between your client and the server. It did prefetch network responses in the past (I think before 3.2.0
?) but it was the cause of the OOM issues and I would consider it also a UX bug. If you are not interested in the response neither is Chucker.Colton Idle
08/14/2020, 4:19 AMthe response is still read. closing spends up to 100ms discarding the body before it simply abandons the connection
MiSikora
08/14/2020, 6:47 AMVoid
and Unit
types. So what you experience with Chucker is 100% correct. If you (or more precisely Retrofit) do not read body bytes over the connection why Chucker should?
Unit
and Void
are reserved in Retrofit for closing the response body stream without reading it https://github.com/square/retrofit/blob/65de04d1da61f9e8124956f6fff8902fc81d05e2/retrofit/src/main/java/retrofit2/BuiltInConverters.java#L66-L84. You can add a converter for Any
that reads the bytes and represent your model with that type, since it would make more sense in context of Retrofit
.Colton Idle
08/14/2020, 7:00 AMIf you (or more precisely Retrofit) do not read body bytes over the connection why Chucker should?I'm not sure I agree. I get your point, but hopefully you can see my point... from a network inspector perspective... it's "wrong" (IMO) for it to not show a response body. I'm still getting the response. Charles shows the response. Chuck shows the response. Chucker does not.
MiSikora
08/14/2020, 7:23 AMColton Idle
08/14/2020, 12:58 PMRetrofit does read the response but does not read response bodyIs that correct? Just trying to figure out why having a return of Response<Unit> does not populate the response body in the network interceptor. Jake Wharton [JW] [8:14 AM] It has no effect on the actual request or response
MiSikora
08/14/2020, 1:00 PMColton Idle
08/14/2020, 3:53 PMMiSikora
08/14/2020, 5:43 PMChucker works as an OkHttp Interceptor persisting all those events inside your application, and providing a UI for inspecting and sharing their content.
- for me it’s quite clear what is the expected output. If no bytes go through the interceptor then nothing will be observed. It rather comes down to the knowledge how Retrofit treats Unit
and Void
.
Anyway, to solve your problem you can add a converter like this to your Retrofit instance. It will allow you to use suspend fun foo(): Response<Any>
object AnyReadingConverterFactory : Converter.Factory() {
override fun responseBodyConverter(type: Type, annotations: Array<Annotation>, retrofit: Retrofit): Converter<ResponseBody, *>? {
return if (type == Any::class.java) AnyConverter else null
}
private object AnyConverter : Converter<ResponseBody, Any> {
private val any = Any()
override fun convert(value: ResponseBody): Any? {
value.source().use { it.readAll(Okio.blackhole()) }
return any
}
}
}