package Ġcom . dc . ret ro api . interceptor Ċ Ċ import Ġokhttp 3 . Interceptor Ċ import Ġokhttp 3 . Response Ċ import Ġokhttp 3 . ResponseBody . Companion . to ResponseBody Ċ Ċ class ĠResponse Interceptor ( private Ġval Ġon Response Callback : ĠOn Response Callback ) Ġ: ĠInter ceptor Ġ{ ĊĊĠĠĠ Ġinterface ĠOn Response Callback Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġon Network Response ( response : ĠResponse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġintercept ( chain : ĠInter ceptor . Chain ): ĠResponse Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoriginal Response Ġ= Ġchain . proceed ( chain . request ()) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Body Ġ= Ġoriginal Response . body ĊĠĠĠĠĠĠĠ Ġif Ġ( response Body Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġoriginal Response String Ġ= Ġresponse Body . string () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnew ResponseBody Ġ= Ġoriginal Response String . to ResponseBody ( response Body . contentType ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Response Callback . on Network Response ( original Response . newBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( original Response String . to ResponseBody ( response Body . contentType ())). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġoriginal Response . newBuilder (). body ( new ResponseBody ). build () ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Response Callback . on Network Response ( original Response . newBuilder (). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġoriginal Response . newBuilder (). build () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ } Ċ