package com.yidian.common.http

import com.orhanobut.hawk.Hawk
import com.yidian.common.HawkConfig
import okhttp3.Interceptor
import okhttp3.Response

class ApiSaveCookiesInterceptor: Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val originalResponse = chain.proceed(chain.request())

        val cookieList = originalResponse.headers("Set-Cookie")
        if (cookieList.isNotEmpty()) {
            for (cookie in cookieList) {
                if(cookie.contains("JSESSIONID")){
                    Hawk.put(HawkConfig.Cookie, cookie)
                }
            }
        }
        return originalResponse
    }
}