package com.lukouguoji.module_base.http.net

import com.lukouguoji.module_base.http.net.body.ProgressResponseBody
import okhttp3.Interceptor
import okhttp3.Response


class ProgressInterceptor(
    private val progressCallback: (url: String, total: Long, current: Long, progress: Int) -> Unit
) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val proceed = chain.proceed(chain.request())
        return proceed
            .newBuilder()
            .body(
                ProgressResponseBody(
                    chain.request().url.toString(),
                    proceed.body!!,
                    progressCallback
                )
            )
            .build()
    }
}