diff --git a/DisCatSharp/Clients/DiscordClient.WebSocket.cs b/DisCatSharp/Clients/DiscordClient.WebSocket.cs
index 04e1db8762..77700cf6e1 100644
--- a/DisCatSharp/Clients/DiscordClient.WebSocket.cs
+++ b/DisCatSharp/Clients/DiscordClient.WebSocket.cs
@@ -165,16 +165,16 @@ internal async Task InternalConnectAsync()
this.WebSocketClient.MessageReceived += SocketOnMessage;
this.WebSocketClient.ExceptionThrown += SocketOnException;
- var gwuri = new QueryUriBuilder(this.GatewayUri)
- .AddParameter("v", this.Configuration.ApiVersion)
- .AddParameter("encoding", "json");
+ var gwuri = this.GatewayUri.AddParameter("v", this.Configuration.ApiVersion).AddParameter("encoding", "json");
if (this.Configuration.GatewayCompressionLevel == GatewayCompressionLevel.Stream)
- gwuri.AddParameter("compress", "zlib-stream");
+ gwuri = gwuri.AddParameter("compress", "zlib-stream");
+
+ this.GatewayUri = gwuri;
this.Logger.LogDebug(LoggerEvents.Startup, "Connecting to {gw}", this.GatewayUri.AbsoluteUri);
- await this.WebSocketClient.ConnectAsync(gwuri.Build()).ConfigureAwait(false);
+ await this.WebSocketClient.ConnectAsync(this.GatewayUri).ConfigureAwait(false);
return;
Task SocketOnConnect(IWebSocketClient sender, SocketEventArgs e)
diff --git a/DisCatSharp/Utilities.cs b/DisCatSharp/Utilities.cs
index 34ed639368..67f2a6bb64 100644
--- a/DisCatSharp/Utilities.cs
+++ b/DisCatSharp/Utilities.cs
@@ -10,6 +10,7 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
+using System.Web;
using DisCatSharp.Common;
using DisCatSharp.Common.RegularExpressions;
@@ -89,6 +90,23 @@ static Utilities()
VersionHeader = $"DiscordBot (https://github.com/Aiko-IT-Systems/DisCatSharp, v{vs})";
}
+ ///
+ /// Adds the specified parameter to the Query String.
+ ///
+ ///
+ /// Name of the parameter to add.
+ /// Value for the parameter to add.
+ /// Url with added parameter.
+ public static Uri AddParameter(this Uri url, string paramName, string paramValue)
+ {
+ var uriBuilder = new UriBuilder(url);
+ var query = HttpUtility.ParseQueryString(uriBuilder.Query);
+ query[paramName] = paramValue;
+ uriBuilder.Query = query.ToString();
+
+ return uriBuilder.Uri;
+ }
+
///
/// Gets the api base uri.
///