content: /**
   * Copyright (C) 2024 AIDC-AI
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.alibaba.langengine.minimax.model;
  
  import java.io.IOException;
  
  import lombok.extern.slf4j.Slf4j;
  import okhttp3.Interceptor;
  import okhttp3.Request;
  import okhttp3.Response;
  
  /**
   * @author aihe.ah
   * @time 2023/12/18
   * 功能说明：
   */
  @Slf4j
  public class HttpLoggingInterceptor implements Interceptor {
  
      @Override
      public Response intercept(Chain chain) throws IOException {
          Request request = chain.request();
  
          long t1 = System.nanoTime();
          log.info(String.format("Sending request %s on %s%n%s",
              request.url(), chain.connection(), request.headers()));
  
          Response response = chain.proceed(request);
  
          long t2 = System.nanoTime();
          log.info(String.format("Received response for %s in %.1fms%n%s",
              response.request().url(), (t2 - t1) / 1e6d, response.headers()));
  
          // 注意：如果你打印response.body().string()，你将消耗响应体，并且它将无法再次被读取
          // 如果你需要打印响应体，确保重新创建响应体或者只打印部分信息
          log.info(response.body().string());
  
          return response;
      }
  }
  