From e2389d96e987d5b2ad28a8ef1c973494d4d8d3e0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 3 Nov 2018 01:39:28 -0400 Subject: [PATCH] Include implementation in the user-agent. --- .../proxy/network/http/NettyHttpClient.java | 4 +++- .../proxy/network/http/SimpleHttpResponse.java | 8 ++++---- .../proxy/plugin/VelocityEventManager.java | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java b/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java index 66fd27fd8..dd79addde 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/http/NettyHttpClient.java @@ -25,8 +25,10 @@ import javax.net.ssl.SSLEngine; public class NettyHttpClient { private final ChannelPoolMap poolMap; + private final String userAgent; public NettyHttpClient(VelocityServer server) { + this.userAgent = server.getVersion().getName() + "/" + server.getVersion().getVersion(); Bootstrap bootstrap = server.initializeGenericBootstrap(); this.poolMap = new AbstractChannelPoolMap() { @Override @@ -80,7 +82,7 @@ public class NettyHttpClient { DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, url.getPath() + "?" + url.getQuery()); request.headers().add(HttpHeaderNames.HOST, url.getHost()); - request.headers().add(HttpHeaderNames.USER_AGENT, "Velocity"); + request.headers().add(HttpHeaderNames.USER_AGENT, userAgent); channel.writeAndFlush(request); // Make sure to release this connection diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponse.java index c5947def6..3bcfdc40a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/http/SimpleHttpResponse.java @@ -20,9 +20,9 @@ public class SimpleHttpResponse { @Override public String toString() { - return "SimpleHttpResponse{" + - "code=" + code + - ", body='" + body + '\'' + - '}'; + return "SimpleHttpResponse{" + + "code=" + code + + ", body='" + body + '\'' + + '}'; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java index c1e9a5dcb..812b7d0b9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityEventManager.java @@ -68,8 +68,7 @@ public class VelocityEventManager implements EventManager { ensurePlugin(plugin); Preconditions.checkNotNull(listener, "listener"); if (plugin == listener && registeredListenersByPlugin.containsEntry(plugin, plugin)) { - throw new IllegalArgumentException( - "Trying to register the plugin main instance. Velocity already takes care of this for you."); + throw new IllegalArgumentException("The plugin main instance is automatically registered."); } registeredListenersByPlugin.put(plugin, listener); methodAdapter.register(listener);