package chat.rocket.android.helper;

import android.content.Context;
import com.facebook.stetho.okhttp3.StethoInterceptor;

import java.util.concurrent.TimeUnit;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.rest.CookieInterceptor;
import chat.rocket.android.api.rest.DefaultCookieProvider;
import okhttp3.OkHttpClient;

/**
 * Helper class for OkHttp client.
 */
public class OkHttpHelper {
  private static OkHttpClient httpClientForUploadFile;
  private static OkHttpClient httpClientForDownloadFile;
  private static OkHttpClient httpClientForWS;

  public static OkHttpClient getClientForDownloadFile(Context context) {
    if (httpClientForDownloadFile == null) {
      httpClientForDownloadFile = new OkHttpClient.Builder()
          .addNetworkInterceptor(new StethoInterceptor())
          .addInterceptor(
              new CookieInterceptor(new DefaultCookieProvider(new RocketChatCache(context))))
          .build();
    }
    return httpClientForDownloadFile;
  }

  public static OkHttpClient getClientForUploadFile() {
    if (httpClientForUploadFile == null) {
      httpClientForUploadFile = new OkHttpClient.Builder()
          .addNetworkInterceptor(new StethoInterceptor())
          .build();
    }
    return httpClientForUploadFile;
  }

  /**
   * acquire OkHttpClient instance for WebSocket connection.
   */
  public static OkHttpClient getClientForWebSocket() {
    if (httpClientForWS == null) {
      httpClientForWS = new OkHttpClient.Builder().readTimeout(0, TimeUnit.NANOSECONDS)
          .addNetworkInterceptor(new StethoInterceptor())
          .build();
    }
    return httpClientForWS;
  }
}

@@ -62,16 +62,59 @@
 ontext;%0A
+import android.support.annotation.NonNull;%0A
 import c
@@ -156,24 +156,52 @@
 terceptor;%0A%0A
+import java.io.IOException;%0A
 import java.
@@ -399,28 +399,123 @@
 okhttp3.
-OkHttpClient
+Call;%0Aimport okhttp3.Callback;%0Aimport okhttp3.OkHttpClient;%0Aimport okhttp3.Request;%0Aimport okhttp3.Response
 ;%0A%0A/**%0A 
@@ -580,16 +580,65 @@
 elper %7B%0A
+  private static OkHttpClient defaultHttpClient;%0A
   privat
@@ -787,16 +787,231 @@
 ntForWS;
+%0A  private static String contentType;%0A%0A  public static OkHttpClient getDefaultHttpClient() %7B%0A    if (defaultHttpClient == null) %7B%0A      defaultHttpClient = new OkHttpClient();%0A    %7D%0A    return defaultHttpClient;%0A  %7D
 %0A%0A  publ
@@ -2080,11 +2080,740 @@
 rWS;%0A  %7D
+%0A%0A  public static String getContentType(String uri) %7B%0A    Request request = new Request.Builder()%0A        .url(uri)%0A        .head()%0A        .build();%0A    getDefaultHttpClient().newCall(request).enqueue(new Callback() %7B%0A      @Override%0A      public void onFailure(@NonNull Call call, @NonNull IOException ioException) %7B%0A        ioException.printStackTrace();%0A      %7D%0A%0A      @Override%0A      public void onResponse(@NonNull Call call, @NonNull final Response response)%0A          throws IOException %7B%0A        if (!response.isSuccessful()) %7B%0A          throw new IOException(%22Unexpected code: %22 + response);%0A        %7D else %7B%0A          contentType = response.header(%22Content-Type%22);%0A        %7D%0A      %7D%0A    %7D);%0A    return contentType;%0A  %7D
 %0A%7D%0A

Add getContentType(...) and getDefaultHttpClient() method.