package com.yidian.bcommon.http

import com.orhanobut.hawk.Hawk
import com.yidian.bcommon.constant.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
  }
}
