http-api: Include commit hash in User-Agent

This commit is contained in:
Max Weber
2019-01-30 17:52:06 -07:00
committed by Adam
parent 9ab9437936
commit f17633daf9
3 changed files with 40 additions and 3 deletions

View File

@@ -44,6 +44,7 @@ public class RuneLiteAPI
public static final OkHttpClient CLIENT;
public static final Gson GSON = new Gson();
public static String userAgent;
private static final String BASE = "https://api.runelite.net";
private static final String WSBASE = "wss://api.runelite.net/runelite-";
@@ -61,6 +62,10 @@ public class RuneLiteAPI
version = properties.getProperty("runelite.version");
rsVersion = Integer.parseInt(properties.getProperty("rs.version"));
String commit = properties.getProperty("runelite.commit");
boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty"));
userAgent = "RuneLite/" + version + "-" + commit + (dirty ? "+" : "");
}
catch (NumberFormatException e)
{
@@ -74,14 +79,13 @@ public class RuneLiteAPI
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)
.header("User-Agent", userAgent)
.build();
return chain.proceed(userAgentRequest);
}

View File

@@ -1,2 +1,4 @@
runelite.version=${project.version}
rs.version=${rs.version}
rs.version=${rs.version}
runelite.commit=${git.commit.id.abbrev}
runelite.dirty=${git.dirty}