http api: add runelite user agent to requests

This commit is contained in:
Adam
2019-01-11 10:09:48 -05:00
parent c18185c097
commit 0f8a9b934a
3 changed files with 91 additions and 1 deletions

View File

@@ -29,7 +29,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +42,7 @@ public class RuneLiteAPI
public static final String RUNELITE_AUTH = "RUNELITE-AUTH";
public static final OkHttpClient CLIENT = new OkHttpClient();
public static final OkHttpClient CLIENT;
public static final Gson GSON = new Gson();
private static final String BASE = "https://api.runelite.net";
@@ -67,6 +70,23 @@ public class RuneLiteAPI
{
logger.error(null, ex);
}
CLIENT = new OkHttpClient.Builder()
.addNetworkInterceptor(new Interceptor()
{
private final String USER_AGENT = "RuneLite/" + version;
@Override
public Response intercept(Chain chain) throws IOException
{
Request userAgentRequest = chain.request()
.newBuilder()
.header("User-Agent", USER_AGENT)
.build();
return chain.proceed(userAgentRequest);
}
})
.build();
}
public static HttpUrl getApiRoot()