Move okhttp client from http-api
The client has been recreated with a new builder off of the http-api client for awhile anyway since runelite-client has multiple other requirements (caching, tls, etc). This fully moves creation of the okhttp client into both http-service and runelite-client separately. I've kept the CLIENT field in http-api for now since a few external plugins depend on it currently.
This commit is contained in:
@@ -27,78 +27,25 @@ package net.runelite.http.api;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Instant;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.Getter;
|
||||
import net.runelite.http.api.gson.ColorTypeAdapter;
|
||||
import net.runelite.http.api.gson.IllegalReflectionExclusion;
|
||||
import net.runelite.http.api.gson.InstantTypeAdapter;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RuneLiteAPI
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(RuneLiteAPI.class);
|
||||
|
||||
public static final String RUNELITE_AUTH = "RUNELITE-AUTH";
|
||||
public static final String RUNELITE_MACHINEID = "RUNELITE-MACHINEID";
|
||||
|
||||
public static final OkHttpClient CLIENT;
|
||||
@Deprecated
|
||||
public static OkHttpClient CLIENT;
|
||||
public static final Gson GSON;
|
||||
public static final MediaType JSON = MediaType.parse("application/json");
|
||||
public static String userAgent;
|
||||
|
||||
private static final Properties properties = new Properties();
|
||||
@Getter
|
||||
private static String version;
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream in = RuneLiteAPI.class.getResourceAsStream("/runelite.properties");
|
||||
properties.load(in);
|
||||
|
||||
version = properties.getProperty("runelite.version");
|
||||
String commit = properties.getProperty("runelite.commit");
|
||||
boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty"));
|
||||
|
||||
userAgent = "RuneLite/" + version + "-" + commit + (dirty ? "+" : "");
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new RuntimeException("Version string has not been substituted; Re-run maven");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error(null, ex);
|
||||
}
|
||||
|
||||
CLIENT = new OkHttpClient.Builder()
|
||||
.pingInterval(30, TimeUnit.SECONDS)
|
||||
.addNetworkInterceptor(new Interceptor()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException
|
||||
{
|
||||
Request userAgentRequest = chain.request()
|
||||
.newBuilder()
|
||||
.header("User-Agent", userAgent)
|
||||
.build();
|
||||
return chain.proceed(userAgentRequest);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
|
||||
gsonBuilder
|
||||
|
||||
Reference in New Issue
Block a user