title: How to add headers to OkHttp request interceptor?
body: <p>I have this interceptor that i add to my OkHttp client:</p>
  
  <pre><code>public class RequestTokenInterceptor implements Interceptor {
  @Override
  public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    // Here where we'll try to refresh token.
    // with an retrofit call
    // After we succeed we'll proceed our request
    Response response = chain.proceed(request);
    return response;
  }
  }
  </code></pre>
  
  <p>How can i add headers to request in my interceptor?</p>
  
  <p>I tried this but i am making mistake and i lose my request when creating new request:</p>
  
  <pre><code>    public class RequestTokenInterceptor implements Interceptor {
      @Override
      public Response intercept(Interceptor.Chain chain) throws IOException {
          Request request = chain.request();
          Request newRequest;
  
          try {
              Log.d("addHeader", "Before");
              String token = TokenProvider.getInstance(mContext).getToken();
              newRequest = request.newBuilder()
                      .addHeader(HeadersContract.HEADER_AUTHONRIZATION, O_AUTH_AUTHENTICATION + token)
                      .addHeader(HeadersContract.HEADER_CLIENT_ID, CLIENT_ID)
                      .build();
          } catch (Exception e) {
              Log.d("addHeader", "Error");
              e.printStackTrace();
              return chain.proceed(request);
          }
  
          Log.d("addHeader", "after");
          return chain.proceed(newRequest);
      }
  }
  </code></pre>
  
  <p>Note that, i know i can add header when creating request like this:</p>
  
  <pre><code>Request request = new Request.Builder()
      .url("https://api.github.com/repos/square/okhttp/issues")
      .header("User-Agent", "OkHttp Headers.java")
      .addHeader("Accept", "application/json; q=0.5")
      .addHeader("Accept", "application/vnd.github.v3+json")
      .build();
  </code></pre>
  
  <p>But it doesn't fit my needs. I need it in interceptor.</p>