package com.tofly.latte_core.net.interceptor;

import android.util.Log;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

/**
 * Author:Rivan
 * CreateTime:2021/3/29 18:22
 * Description:
 */
public class LogInterceptor implements Interceptor {

    private String TAG = "LogInterceptor";

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        Request request = builder.build();
        Response response = chain.proceed(request);
        Log.e(TAG, "request:" + request.toString());
        //Log.e(TAG, "headers: " + response.headers());
        ResponseBody requestBody = response.peekBody(1024 * 1024);
        String content = requestBody.string();
        Log.e(TAG, "response body:" + content);
        return response;
    }

}
